序言为什么在调用HtmlHelper.AntiForgeryToken时会出现TypeInitializationException?
我已经搜查,看看我是否可以在任何地方上在这里找到这个问题,我不能。 I previously asked on meta如果报告SO上的错误是有效的。
我的共识是,我应该从源头报告错误,如果我感受到社区的头脑,也许会问及回答SO的问题,以便其他人可能会遇到它。所以我在这里做我的社区位。
问题
我有一个要求Html.AntiForgeryToken
它抛出一个FormatterGenerator
的TypeInitializationException
MVC视图。堆栈跟踪如下(道歉滚动条):
The virtual path '[path]' maps to another application, which is not allowed [ArgumentException: The virtual path '/Asp%20Net%20Bug%202008/Account/Register' maps to another application, which is not allowed.] System.Web.CachedPathData.GetVirtualPathData(VirtualPath virtualPath, Boolean permitPathsOutsideApp) +11193138 System.Web.HttpContext.GetFilePathData() +61 System.Web.Configuration.HttpCapabilitiesBase.GetBrowserCapabilities(HttpRequest request) +124 System.Web.HttpRequest.get_Browser() +168 System.Web.UI.Page.SetIntrinsics(HttpContext context, Boolean allowAsync) +207 System.Web.UI.Page.ProcessRequest(HttpContext context) +232 System.Web.Mvc.TokenPersister.CreateFormatterGenerator() +459 System.Web.Mvc.FormatterGenerator..cctor() +10 [TypeInitializationException: The type initializer for 'FormatterGenerator' threw an exception.] System.Web.Mvc.AntiForgeryDataSerializer.get_Formatter() +38 System.Web.Mvc.AntiForgeryDataSerializer.Serialize(AntiForgeryData token) +181 System.Web.Mvc.HtmlHelper.GetAntiForgeryTokenAndSetCookie(String salt, String domain, String path) +405 System.Web.Mvc.HtmlHelper.AntiForgeryToken(String salt, String domain, String path) +13 System.Web.Mvc.HtmlHelper.AntiForgeryToken() +17 ASP.views_account_register_aspx.__RenderregisterContent(HtmlTextWriter __w, Control parameterContainer) in c:\Users\andras.zoltan\documents\visual studio 2008\projects\aspnetbug2008\aspnetbug2008\Views\Account\Register.aspx:17 System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +115 ASP.views_shared_site_master.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in c:\Users\andras.zoltan\documents\visual studio 2008\projects\aspnetbug2008\aspnetbug2008\Views\Shared\Site.Master:26 System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +115 System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +240 System.Web.UI.Page.Render(HtmlTextWriter writer) +38 System.Web.Mvc.ViewPage.Render(HtmlTextWriter writer) +89 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4240
更奇怪的是,当他们加载了该项目,并运行一个同事没有得到这个问题。
我的环境是VS2008和IIS7.5;这是一个MVC2项目。