【问题标题】:ASP.NET MVC 3 AntiForgeryToken and custom MachineKey configurationASP.NET MVC 3 AntiForgeryToken 和自定义 MachineKey 配置
【发布时间】:2011-05-20 07:42:44
【问题描述】:

当在 Web.Config 中有自定义配置的 MachineKey 时,我们遇到了 ASP.NET MVC 3 AntiForgeryToken HTML 帮助程序的一些问题。如果您将 MachineKey 更改为以下内容,则该错误很容易重现(取自 Microsoft HowTo-guide on how to configure machine key)。

<machineKey  
    validationKey="21F090935F6E49C2C797F69BBAAD8402ABD2EE0B667A8B44EA7DD4374267A75D7
           AD972A119482D15A4127461DB1DC347C1A63AE5F1CCFAACFF1B72A7F0A281B"           
    decryptionKey="ABAA84D7EC4BB56D75D217CECFFB9628809BDB8BF91CFCD64568A145BE59719F"
    validation="SHA1"
    decryption="AES"/>

AntiForgeryToken抛出的异常如下:

[IndexOutOfRangeException: Index was outside the bounds of the array.]
   System.Web.Configuration.MachineKeySection.SetInnerOuterKeys(Byte[] validationKey, Byte[]& inner, Byte[]& outer) +11499173
   System.Web.Configuration.MachineKeySection.ConfigureEncryptionObject() +228
   System.Web.Configuration.MachineKeySection.EnsureConfig() +287
   System.Web.Configuration.MachineKeySection.HashData(Byte[] buf, Byte[] modifier, Int32 start, Int32 length) +46
   System.Web.Security.MachineKey.Encode(Byte[] data, MachineKeyProtection protectionOption) +58
   System.Web.Helpers.AntiForgeryDataSerializer.<.ctor>b__2(Byte[] bytes) +13
   System.Web.Helpers.AntiForgeryDataSerializer.Serialize(AntiForgeryData token) +365
   System.Web.Helpers.AntiForgeryWorker.GetAntiForgeryTokenAndSetCookie(HttpContextBase httpContext, String salt, String domain, String path) +326
   System.Web.Helpers.AntiForgeryWorker.GetHtml(HttpContextBase httpContext, String salt, String domain, String path) +28
   System.Web.Helpers.AntiForgery.GetHtml(HttpContextBase httpContext, String salt, String domain, String path) +75
   System.Web.Mvc.HtmlHelper.AntiForgeryToken(String salt, String domain, String path) +48

这是 ASP.NET MVC 3 Html Helper 中生成 AntiForgeryToken 的错误吗?还是我在配置机器密钥方面遗漏了什么?

【问题讨论】:

标签: asp.net security asp.net-mvc-3 web-config cryptography


【解决方案1】:

看起来我搞砸了密钥 - 使用 http://aspnetresources.com/tools/machineKey 我能够生成有效的 machineKey 配置部分。

【讨论】:

    猜你喜欢
    • 2011-10-02
    • 2013-02-05
    • 2015-12-13
    • 1970-01-01
    • 1970-01-01
    • 2011-11-23
    • 2011-08-23
    • 2018-06-11
    • 2013-07-22
    相关资源
    最近更新 更多