EDIT:__RequestVerificationToken can not found when using nginx, why?
Rhis is my validation code, it always returns an error when using nginx, if I do not use nginx, it is OK. We are using nginx because we have many machines to point at the same host. Rhanks.
public class MyValidateAntiForgeryToken : AuthorizeAttribute
{
public override void OnAuthorization(AuthorizationContext filterContext)
{
var request = filterContext.HttpContext.Request;
if (request.HttpMethod== WebRequestMethods.Http.Post)
{
if (request.IsAjaxRequest())
{
var antiForgeryCookie = request.Cookies[AntiForgeryConfig.CookieName];
var cookieValue = antiForgeryCookie != null
? antiForgeryCookie.Value : null;
AntiForgery.Validate(cookieValue, request.Headers["__RequestVerificationToken"]);
}
else
{
new ValidateAntiForgeryTokenAttribute()
.OnAuthorization(filterContext);
}
}
}
this is my front code:
var token = $('@Html.AntiForgeryToken()').val();
var headers = {};
headers["__RequestVerificationToken"] = token;
$.ajax({
type: 'POST',
url: '@Url.Action("BuyProduct", "PpdaiVip")',
cache: false,
headers: headers,
data: arr,
success: function (e) {
if (e.IsSuccess) {
}
});