Hi I’m using a custom role provider and all seems to be working fine, if the user has permissions they are allowed in if not they are redirected to the login page.
But what I wanted to know is when they get redirected to the login page is there a way in the login page to set a message saying access denied or something.
So for example I want something like below, User.FailedCustomRole? I’m not sure if something like this exists in an object somewhere:
[AllowAnonymous]
public ActionResult Login()
{
if (User.FailedCustomRole) {
ViewBag.Message = "No access to this page";
}
return View();
}
Thanks
One way is to alter web.config to redirect user to the Logon page with a parameter of 1.
Alter your Logon Action to take a nullable int and if set, add a modelstate error
A second way is to create an action filter that checks for login and redirects setting a Viewbag.LoginError
add to your login page a div that shows
@(Viewbag.LoginError). This would render blank if unpopulated.A third way is to create a custom Authorization filter which redirects and sets an error message in a V@(ViewData[“LoginError”].
add to your login page a div that shows
@(ViewData["LoginError"]. This would render blank if unpopulated.note I’m least certain or comfortable with this last method.