Asp.net mvc 5 使用Authorize(Roles=";Customer,Business";)调用Action会为这些角色返回500个错误

Asp.net mvc 5 使用Authorize(Roles=";Customer,Business";)调用Action会为这些角色返回500个错误,asp.net-mvc-5,asp.net-identity-2,Asp.net Mvc 5,Asp.net Identity 2,我的MVC站点中有几个操作最近开始返回身份验证错误,当我使用具有授权角色的帐户登录时调用这些操作。下面是一个例子 [HttpGet] [Authorize(Roles = "Customer, Business")] public async Task<ActionResult> ShowNotifications(bool unViewedOnly = true) { var userId = User.Identity.GetUserId<int>();

我的MVC站点中有几个操作最近开始返回身份验证错误,当我使用具有授权角色的帐户登录时调用这些操作。下面是一个例子

[HttpGet]
[Authorize(Roles = "Customer, Business")]
public async Task<ActionResult> ShowNotifications(bool unViewedOnly = true) {
    var userId = User.Identity.GetUserId<int>();
    var notifications = await _notifications.GetByUserIdAsync(userId, unViewedOnly);
    return (Request.IsAjaxRequest())
        ? PartialView("Notifications/NotificationsModal", notifications)
        : PartialView("Notifications/_Notifications", notifications);
}

我将查看登录时创建的标识对象。角色应该是索赔令牌的一部分。我如何观察此对象?这一切都隐藏在Ninject和身份框架背后,我似乎无法进入其中。我错过什么了吗?没关系。我明白你的意思了。我以为你指的是别的东西。好的,在观察Identity对象时,我看到它包含所需的角色。仅当我使用[AllowAnonymous][Authorize(Roles=“xxxxx”)]无效时,该操作才有效。一件可能相关的事情是,我也有一个类的授权(角色)。这可能是问题吗?是的,这可能是问题所在。您可以将授权属性堆叠在彼此的顶部。它们不会“覆盖”。
Key Value
X-Responded-JSON    {"status":401,"headers":{"location":"http:\/\/localhost:53033\/Account\/Login?ReturnUrl=%2FShared%2FShowNotifications%3FunViewedOnly%3DTrue%26modal%3DTrue%26X-Requested-With%3DXMLHttpRequest%26_%3D1426264188044"}}