Monday, 15 August 2011

asp.net - MVC Custom role provider redirect to login page -



asp.net - MVC Custom role provider redirect to login page -

hi i'm using custom role provider , seems working fine, if user has permissions allowed in if not redirected login page.

but wanted know when redirected login page there way in login page set message saying access denied or something. illustration want below, user.failedcustomrole? i'm not sure if exists in object somewhere:

[allowanonymous] public actionresult login() { if (user.failedcustomrole) { viewbag.message = "no access page"; } homecoming view(); }

thanks

one way alter web.config redirect user logon page parameter of 1.

alter logon action take nullable int , if set, add together modelstate error

public actionresult logon(int? id) { //int id = request.querystring[; if (id != null) { logonmodel model = new logonmodel(); modelstate.addmodelerror("", "please login utilize page"); homecoming view(model); }

a sec way create action filter checks login , redirects setting viewbag.loginerror

public class checkloginfilterattribute : actionfilterattribute { public override void onactionexecuting(actionexecutedcontext filtercontext) { if (membership.getuser() != null) { viewbag.loginerror = "please login utilize page"; filtercontext.result = new redirecttorouteresult( new system.web.routing.routevaluedictionary { {"controller", "account"}, {"action", "logon"} } { } base.onactionexecuted(filtercontext); }

add login page div shows @(viewbag.loginerror). render blank if unpopulated.

a 3rd way create custom authorization filter redirects , sets error message in v@(viewdata["loginerror"].

add login page div shows @(viewdata["loginerror"]. render blank if unpopulated.

note i'm to the lowest degree or comfortable lastly method.

asp.net asp.net-mvc asp.net-mvc-3 asp.net-mvc-4

No comments:

Post a Comment