【发布时间】:2012-10-12 11:09:32
【问题描述】:
我们有一个用 ASP.NET MVC 3 编写的应用程序,它使用 @Html.AntiForgeryToken()。
我们想要验证自定义属性中的令牌(无需指定默认属性[ValidateAntiForgeryToken])。这应该很简单,但我发现了一个有趣的不一致之处。
-
以下所有代码都在以下方法中运行:
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = false, Inherited = true)] public class ValidateJsonAntiForgeryTokenAttribute : FilterAttribute, IAuthorizationFilter { public void OnAuthorization(AuthorizationContext filterContext) { ... AntiForgeryConfig.CookieName的值为__RequestVerificationToken。这似乎有道理。filterContext.HttpContext.Request.Cookies包含 1 个 cookie - 但它的名称是__RequestVerificationToken_Lw__。
问题:这两个不应该是一样的,所以我可以使用下面的sn-p来获取cookie吗?
var cookie = filterContext.HttpContext.Request.Cookies[AntiForgeryConfig.CookieName];
【问题讨论】:
标签: asp.net-mvc-3 antiforgerytoken