Reputation: 46
i'm trying to use IdentityManager (just first), and it looks very greatful, and it is creating the role (it's cool), but why it isn't bind the user with the selected role (int idm), because if when i use the attribute [Authorize(Roles = "Admin")] in Home/Contact (for example) it doesn't work. It doesn't to save the selected roles (from user-interface) to AspNetUserRoles-table in database. It just saved to AspNetClaims-table. Is IdentityManager's bug?
Upvotes: 2
Views: 109
Reputation: 2455
You can try AuthorizeAttribute
and set custom error message in it.
public class WebApiAuthorizeAttribute : AuthorizeAttribute
{
protected override void HandleUnauthorizedRequest(HttpActionContext actionContext)
{
if (!actionContext.RequestContext.Principal.Identity.IsAuthenticated)
{
//Logic for when api not authenticated
}
base.HandleUnauthorizedRequest(actionContext);
}
}
Controller api method in which above authorize attribute used.
[HttpGet]
[WebApiAuthorizeAttribute(Roles="Admin")]
public async Task<HttpResponseMessage> TestMethod()
{
return Request.CreateResponse(HttpStatusCode.OK);
}
Upvotes: 0