well i guess its from that part of web config cous i haven't set redirect other way.
I would like to know if it is possible to set separatly(for login fail or role fail ) different redirects? So when user is not logon it goes to User/Login and when its logon but not in proper role it gos in other redirect?
Actually, you dont need different redirects...this would be useful for webforms thta has no controllers but just pages, in Mvc you substantially redirect to a controller acxtion method that than can decide to show different Views after having analyzed what
happened.
sorry i used mental shortcut, by different redirect i mean ofcourse to take it to other controler(other to that which i use in authentication by forms)
sorry i used mental shortcut, by different redirect i mean ofcourse to take it to other controler(other to that which i use in authentication by forms)
The point is that still this way I dont understand why you need two controllers! A single controller my handle both cases, and the same control may display different View with a simple if! Once you are in the Action Method of the Controller that handles
the authorization you verify if the user is logged in or if the request failed because of role problems and then split the code into tho branches...and possibly also display different Views.
politech
Member
52 Points
65 Posts
Custom Role Provider redirect
Jun 30, 2012 09:18 AM|LINK
Hello, I implemented my Custom Role provider and now when role authoryzation fials it redirect me to
<authentication mode="Forms">
<forms loginUrl="~/User/Login" timeout="2880" />
</authentication>
well i guess its from that part of web config cous i haven't set redirect other way.
I would like to know if it is possible to set separatly(for login fail or role fail ) different redirects? So when user is not logon it goes to User/Login and when its logon but not in proper role it gos in other redirect?
francesco ab...
All-Star
20954 Points
3286 Posts
Re: Custom Role Provider redirect
Jun 30, 2012 10:19 AM|LINK
Actually, you dont need different redirects...this would be useful for webforms thta has no controllers but just pages, in Mvc you substantially redirect to a controller acxtion method that than can decide to show different Views after having analyzed what happened.
Mvc Controls Toolkit | Data Moving Plug-in Videos
politech
Member
52 Points
65 Posts
Re: Custom Role Provider redirect
Jun 30, 2012 12:52 PM|LINK
sorry i used mental shortcut, by different redirect i mean ofcourse to take it to other controler(other to that which i use in authentication by forms)
CPrakash82
All-Star
18720 Points
2899 Posts
Re: Custom Role Provider redirect
Jun 30, 2012 06:38 PM|LINK
You got two option to do this.
Global.asax.cs --
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
}
web.Config
<customErrors defaultRedirect="ErrorPage.aspx" mode="On">
<error statusCode="401" redirect="~/Views/Shared/AccessDenied.aspx" />
</customErrors>
Or you can handle Application's Error event and get the error code from exeception to decide the action like below.
protected void Application_Error()
{
var exception = Server.GetLastError();
var httpException = exception as HttpException;
var httpCode = httpException.GetHttpCode();
// Do something on http error code.
}
Thanks,
francesco ab...
All-Star
20954 Points
3286 Posts
Re: Custom Role Provider redirect
Jun 30, 2012 09:22 PM|LINK
The point is that still this way I dont understand why you need two controllers! A single controller my handle both cases, and the same control may display different View with a simple if! Once you are in the Action Method of the Controller that handles the authorization you verify if the user is logged in or if the request failed because of role problems and then split the code into tho branches...and possibly also display different Views.
Mvc Controls Toolkit | Data Moving Plug-in Videos
politech
Member
52 Points
65 Posts
Re: Custom Role Provider redirect
Jul 01, 2012 08:09 AM|LINK
how can i do that?
francesco ab...
All-Star
20954 Points
3286 Posts
Re: Custom Role Provider redirect
Jul 01, 2012 05:20 PM|LINK
User.Identity.IsAuthenticated.....User.Identity.IsInRole("aRole")....
Mvc Controls Toolkit | Data Moving Plug-in Videos