【发布时间】:2018-01-10 13:37:01
【问题描述】:
这是我的 ajax 调用:
$J.ajax({
type: 'POST',
url: "/ajax/getCharts",
data: JSON.stringify(cids),
dataType: 'json',
asynch: false
})
这工作......直到昨天
我们正在使用 Microsoft.AspNet.Identity;
昨天我添加了更多用户角色,扩展了默认值,例如“admin”、“user”等。
现在我在我的 ajax.fail 标头中得到了这个错误:
X 响应 JSON: {"status":401,"headers":{"location":"http://localhost:56970/Account/Login?ReturnUrl=%2Fajax%2FgetCharts"}}
哪种方法有意义 - 如果调用未通过身份验证
注意:
在我的 ajaxController 中,我之前已将其注释为这样(有效):
[Authorize(Roles = "User")]
public class ajaxController : BaseController
现在我将其扩展为包含我的新自定义用户角色,例如:
[Authorize(Roles = "Superuser, Poweruser, User")]
public class ajaxController : BaseController
那没用
我也在RegisterRoutes中添加了这个:
var settings = new FriendlyUrlSettings();
settings.AutoRedirectMode = RedirectMode.Off;
routes.EnableFriendlyUrls(settings);
建议:
ASP.NET Calling WebMethod with jQuery AJAX "401 (Unauthorized)"
但是没用
这个页面对我来说毫无意义:
jquery $.ajax call results in 401 unauthorized response when in Chrome or Firefox, but works in IE
我在这里错过了什么?
【问题讨论】:
-
这里完全是吐槽,但应该是 ["Superuser", "Poweruser", "User"] 代替吗?
标签: jquery asp.net asp.net-ajax