2011-08-28 65 views
0

我使用自定义asp.net 3.0籍错误的第二次尝试在MVC注册

登记工作良好,没有问题,但在测试过程中,我发现一个问题 如果我把对未满足例如密码不正确的值asp.net成员设置的标准,然后我得到的服务器验证错误,说我需要修复:

Your account wasn't created. Please correct the errors and try again. 
The password provided is invalid. Please enter a valid password value. 

所以,这时如果把一个新的密码,并点击提交我收到此错误:

Object reference not set to an instance of an object. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object. 

Source Error: 
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. 


Stack Trace: 

[NullReferenceException: Object reference not set to an instance of an object.] 
    System.Web.Security.MachineKey.Decode(String encodedData, MachineKeyProtection protectionOption) +269 
    Microsoft.Web.Mvc.MachineKeyWrapper.Decode(String encodedData, MachineKeyProtection protectionOption) +10 
    Microsoft.Web.Mvc.MvcSerializer.Deserialize(String serializedValue, SerializationMode mode, IMachineKey machineKey) +80 

[SerializationException: Deserialization failed. Verify that the data is being deserialized using the same SerializationMode with which it was serialized. Otherwise see the inner exception.] 
    Microsoft.Web.Mvc.MvcSerializer.Deserialize(String serializedValue, SerializationMode mode, IMachineKey machineKey) +232 
    Microsoft.Web.Mvc.MvcSerializer.Deserialize(String serializedValue, SerializationMode mode) +25 
    Microsoft.Web.Mvc.DeserializingModelBinder.BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) +128 

..... 

有什么想法它可能是什么?

我的控制器看起来就像是:

public virtual ActionResult Register(RegisterModel model, [Deserialize]List<MyModelState> myModelState) 
{ 
    //to stuff 
    //if error save ModelStt in temp data to render it back to hidden form value 
    TempData["MyModelState"] = myModelState; 
} 

在视图我这样做:

@using (Html.BeginForm()) 
{ 
    List<MyModelState> hidden = TempData["MyModelState"] as List<MyModelState>; 

    if (hidden != null) //never null 
    {   
     @Html.Serialize("MyModelState", hidden) 
    } 
} 

我认为这个问题与[Deserialize]List<MyModelState>,但我不能明白为什么它可以heppend因为隐藏的价值表示该对象永不为零并始终以下列格式存在:

<input name="MyModelState" type="hidden" value="2CF80623577311BA401E41727261794F66537562736372697074696F6E44657461...../> 

我在错误发生之前检查MyModelState的值,当它发生错误时,我单击浏览器按钮,确保隐藏值在窗体中存在,并且等于错误发生之前的值,并且它是正确的,在那里看到不好的东西。

+0

你使用共享主机? – Eranga

+0

@Eranga只是locallhost – Joper

回答

0

我列举了同样的例外。

我将web.config,sessionState模式从“InProc”更改为“StateServer”。

<configuration> 
    <system.web> 
    <sessionState mode="StateServer" .../> 
    ... 

(当然,会话状态模式并不一定是 “SateServer”,你可以选择 “SQLServer的”,或 “自定义”。)

然后,它看起来像固定。

请尝试。

相关问题