我在IIS 7.5中使用.NET 2.0运行时有一个简单的.net应用程序,我在web.config中更改了机器密钥以使用以下内容:
<machineKey validationKey="AutoGenerate,IsolateApps" decryptionKey="AutoGenerate,IsolateApps" validation="SHA1"/>
这在本地工作正常,但当我发布到服务器时,我得到一个“HttpException(0x80004005):无法验证数据”每当浏览网站时.我已确保设置编译debug =“false”.将验证方法设置为3DES可以消除此问题,但我们需要使用SHA1.我在这里缺少一些配置选项吗?看下面的堆栈跟踪.
[HttpException (0x80004005): Unable to validate data.] System.Web.Configuration.MachineKeySection.EncryptOrDecryptData(Boolean fEncrypt,Byte[] buf,Byte[] modifier,Int32 start,Int32 length,IVType ivType,Boolean useValidationSymAlgo,Boolean signData) +1008 System.Web.Configuration.MachineKeySection.EncryptOrDecryptData(Boolean fEncrypt,Boolean useValidationSymAlgo) +91 System.Web.UI.Page.EncryptStringWithIV(String s,IVType ivType) +83 System.Web.UI.Page.EncryptString(String s) +30 System.Web.Handlers.RuntimeScriptResourceHandler.GetScriptResourceUrlImpl(List`1 assemblyResourceLists,Boolean zip,Boolean notifyScriptLoaded) +1497 System.Web.Handlers.RuntimeScriptResourceHandler.System.Web.Handlers.IScriptResourceHandler.GetScriptResourceUrl(List`1 assemblyResourceLists,Boolean notifyScriptLoaded) +1148 System.Web.Handlers.RuntimeScriptResourceHandler.System.Web.Handlers.IScriptResourceHandler.GetScriptResourceUrl(Assembly assembly,String resourceName,CultureInfo culture,Boolean notifyScriptLoaded) +152 System.Web.Handlers.ScriptResourceHandler.GetScriptResourceUrl(Assembly assembly,Boolean notifyScriptLoaded) +37 System.Web.UI.ScriptManager.GetScriptResourceUrl(String resourceName,Assembly assembly) +105 System.Web.UI.ScriptRegistrationManager.RegisterClientScriptResource(Control control,Type type,String resourceName) +113 System.Web.UI.ScriptManager.System.Web.UI.IScriptManager.RegisterClientScriptResource(Control control,String resourceName) +14 System.Web.UI.ClientScriptManager.RegisterClientScriptResource(Control control,String resourceName) +53 System.Web.UI.WebControls.Menu.OnPreRender(EventArgs e,Boolean registerScript) +113 System.Web.UI.WebControls.Menu.OnPreRender(EventArgs e) +25 System.Web.UI.Control.PreRenderRecursiveInternal() +80 System.Web.UI.Control.PreRenderRecursiveInternal() +171 System.Web.UI.Control.PreRenderRecursiveInternal() +171 System.Web.UI.Control.PreRenderRecursiveInternal() +171 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint,Boolean includeStagesAfterAsyncPoint) +842
解决方法
您是否在真正的.NET 2.0应用程序池中运行该应用程序? (我问,因为你使用的是IIS 7.5).
如果没有,请记住.NET 4.5框架中的加密算法已发生变化.
如果你需要兼容< .NET 4.5 Framework您需要一个兼容性标记:
<machineKey compatibilityMode="Framework20SP1" />
有关详细信息,请参阅http://msdn.microsoft.com/en-us/library/system.web.configuration.machinekeysection.compatibilitymode.aspx或http://blogs.msdn.com/b/webdev/archive/2012/10/23/cryptographic-improvements-in-asp-net-4-5-pt-2.aspx.