我遇到了MVC4的问题。
@Html.AntiForgeryToken()html助手在我的开发机器上,当我运行项目时,在检查报头(使用Fiddler)时,返回的令牌的名称是
__RequestVerificationToken但是,当部署到IIS7.5版本(Windows2008Item)时,令牌名如下所示:
__RequestVerificationToken_L2V6b3JkZXI1这个在哪里变的?是因为我的应用程序没有部署到IIS的“根文件夹”吗?我的应用程序被部署到
"http://myserver/myapp" instead of "http://myserver"发布于 2013-08-12 20:56:07
在查看了源代码之后,我找到了答案:
http://aspnetwebstack.codeplex.com/SourceControl/latest#src/System.Web.WebPages/Helpers/AntiForgeryConfig.cs是的,因为我的应用程序被部署到了一个路径中,下面的代码附加了编码的等价路径.希望这个发现能省去你的麻烦。
// If the app path is provided, we're generating a cookie name rather than a field name, and the cookie names should
// be unique so that a development server cookie and an IIS cookie - both running on localhost - don't stomp on
// each other.
internal static string GetAntiForgeryCookieName(string appPath)
{
if (String.IsNullOrEmpty(appPath) || appPath == "/")
{
return AntiForgeryTokenFieldName;
}
else
{
return AntiForgeryTokenFieldName + "_" + HttpServerUtility.UrlTokenEncode(Encoding.UTF8.GetBytes(appPath));
}
}发布于 2019-11-19 06:28:02
通过使用下面的参考AntiForgeryConfig class.See可以很容易地解决这个问题。
Namespace:System.Web.Helpers您需要在Application_Start()事件的Global.asax文件下添加下面的代码。
if (AntiForgeryConfig.CookieName.Contains("__RequestVerificationToken"))
{
AntiForgeryConfig.CookieName = "__RequestVerificationToken";
} https://stackoverflow.com/questions/18196440
复制相似问题