html.AntiForgeryToken没有在Nginx上工作?

时间:2016-11-18 06:22:26

标签: c# asp.net asp.net-mvc nginx

编辑: __ RequestVerificationToken 在使用nginx时找不到,为什么?

这是我的验证码,它在使用nginx时总是返回错误,如果我不使用nginx,那就OK了。我们正在使用nginx,因为我们有许多机器指向同一主机。 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);
            }
        }
    }

这是我的正面代码:

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

0 个答案:

没有答案
相关问题