I have an mvc 3 project and I use AD to authorize users. I have a page where only users with the Administrator role should have access.
I made a sign in the work and authorization of users, so only administrators can access the administrative part of the site. My problem is, when users are not administrators, I seem to be unable to show a good error message.
Here is my actionFilterattribute
public class AdminOnlyAttribute : ActionFilterAttribute { public override void OnActionExecuting(ActionExecutingContext filterContext) { base.OnActionExecuting(filterContext); bool isAuthorised = false; IPrincipal user = filterContext.HttpContext.User; if (user.Identity.IsAuthenticated) { if (user.IsInRole("Admin")) { isAuthorised = true; } } if (!isAuthorised) {
And this is my controller for admin
[AdminOnly] public ActionResult Index() {
Any help is appreciated, thanks in advance
source share