【发布时间】:2011-03-26 03:22:13
【问题描述】:
使用 ASP.net MVC v2.0,有什么方法可以更改 __RequestVerificationToken cookie 的名称?为了隐藏我们的底层技术堆栈,我想将 cookie 重命名为无法追溯到 ASP.Net MVC 的名称。
更多信息请访问Steve Sanderson's blog。
【问题讨论】:
标签: asp.net-mvc security cookies antiforgerytoken
使用 ASP.net MVC v2.0,有什么方法可以更改 __RequestVerificationToken cookie 的名称?为了隐藏我们的底层技术堆栈,我想将 cookie 重命名为无法追溯到 ASP.Net MVC 的名称。
更多信息请访问Steve Sanderson's blog。
【问题讨论】:
标签: asp.net-mvc security cookies antiforgerytoken
ASP.NET MVC 3 和 4 允许您通过设置静态 AntiForgeryConfig.CookieName 属性来更改 cookie 名称。
(msdn参考here)
我知道这个问题专门询问了 ASP.NET MVC 2,但这个问题仍然在搜索引擎排名中返回了适当的查询,例如“ASP.NET MVC AntiForgeryToken cookie 名称”。我想我应该在这里添加信息,以免其他人像我一样反编译 ASP.NET MVC 3+ 源代码。
【讨论】:
__RequestVerificationToken。
查看 MVC 2 源代码,我认为无法更改 cookie 名称。 AntiForgeryData 类开始:
private const string AntiForgeryTokenFieldName = "__RequestVerificationToken";
并获取它刚刚调用的 cookie 名称:
string cookieName = AntiForgeryData.GetAntiForgeryTokenName(ViewContext.HttpContext.Request.ApplicationPath);
在 HtmlHelper 类中。它获取应用程序路径并将其转换为 base 64 并将其附加到 __RequestVerificationToken 的末尾,这是您在查看源代码时看到的。
如果您确实需要更改名称,我建议您从 codeplex 下载 MVC 2 源代码,并使用源代码作为参考来创建您自己的 html 帮助程序和防伪令牌。但是在这样做时,您总是可以引入自己的错误...
【讨论】: