加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 无法在机器密钥设置为SHA1时验证数据错误

发布时间:2020-12-15 08:43:30 所属栏目:百科 来源:网络整理
导读:我在IIS 7.5中使用.NET 2.0运行时有一个简单的.net应用程序,我在web.config中更改了机器密钥以使用以下内容: machineKey validationKey="AutoGenerate,IsolateApps" decryptionKey="AutoGenerate,IsolateApps" validation="SHA1"/ 这在本地工作正常,但当我
我在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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读