MVC - How to add custom authorization

preview_player
Показать описание
Simple example that shows how to add custom authorization to mvc project - roles are loaded from database.
How to override Authorize Attribute in Intranet project
Рекомендации по теме
Комментарии
Автор

thank you, this was so helpful. I was able to apply immediately. Simple and clear and to the point.

hutchm
Автор

great! i just needed the first 3:30 min
thansk!

svc
Автор

I have a question. I am trying to implement this to fit alongside Asp.Net Identity I found that if i added this code
public override void filterContext)
{
// If they are authorized, handle accordingly
if
{

}
else
{
// Otherwise redirect to your specific authorized area
filterContext.Result = new
}
}


It will move the user to my unauthorized access page. But i was still getting moved even when logged in with correct role. So i put into debugger and found that it was never hitting anything after this
var isAuthorized =
if (!isAuthorized)
{
return false;
}




so I commented it out and it seems to work. I am assuming that is because is looking at Asp.Net Identity?

mirandajohnson
Автор

Is it only for intranet project or will it also work on internet project?

Imran
Автор

Can we see the full code of your stored procedure in the Model.Context by any chance?

OtaconAlonsus
Автор

i've followed you but i am getting an error in " it says "the AuthorizeUserAccessLevel could not be found"

rbeat
Автор

This is great. Thank you.
How would you reference UserRole in _Layout.cshtml to show/hide navbar links using this logic:

@if (User.IsInRole("Admin"))
{
}

jafischer
welcome to shbcf.ru