ASP.NET MVC 3 AntiForgeryToken and custom MachineKey configuration

emertj

New Member
We've run into some issues with ASP.NET MVC 3 AntiForgeryToken HTML helper when having a custom configured MachineKey in Web.Config. The error is easy to reproduce if you change your MachineKey to the following (taken from Microsoft HowTo-guide on how to configure machine key).\[code\]<machineKey validationKey="21F090935F6E49C2C797F69BBAAD8402ABD2EE0B667A8B44EA7DD4374267A75D7 AD972A119482D15A4127461DB1DC347C1A63AE5F1CCFAACFF1B72A7F0A281B" decryptionKey="ABAA84D7EC4BB56D75D217CECFFB9628809BDB8BF91CFCD64568A145BE59719F" validation="SHA1" decryption="AES"/>\[/code\]The exception thrown by AntiForgeryToken is as follow:\[code\][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\[/code\]Is this a bug in the ASP.NET MVC 3 Html Helper to generate the AntiForgeryToken? Or am I missing something in regards to configuring machine keys?
 
Top