gpt4 book ai didi

asp.net-mvc-4 - MVC4 AntiForgery token cookie 名称附加随机字符串

转载 作者:行者123 更新时间:2023-12-01 08:31:50 24 4
gpt4 key购买 nike

我遇到了 MVC4 的问题

@Html.AntiForgeryToken()

html 助手。在我的开发机器上,当我运行项目时,在检查 header (使用 Fiddler)时,返回的 token 名称是

__RequestVerificationToken

但当部署到 IIS 版本 7.5 (Windows 2008 R2) 时, token 名称如下所示:

__RequestVerificationToken_L2V6b3JkZXI1

这在哪里发生了变化?是不是因为我的应用程序没有部署到 IIS 的“根文件夹”?例如。我的应用程序部署到

"http://myserver/myapp" instead of "http://myserver"

最佳答案

看了源码找到了答案:

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));
}
}

关于asp.net-mvc-4 - MVC4 AntiForgery token cookie 名称附加随机字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18196440/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com