asp.net mvc - Using Status Description on HttpUnauthorizedResult -
in mvc application call httpunauthorizedresult class , specify statusdescription parameter.
if (!canadd) { return new httpunauthorizedresult("you not have access add"); }
this redirects me login method on accountcontroller , redirect them appropriate screen.
public actionresult login(string returnurl) { if (websecurity.isauthenticated) { return redirecttoaction("accessdenied"); } viewbag.returnurl = returnurl; return view(); }
my question how take advantage of status descripton parameter, nice display these details in accessdenied view.
got same issue. used tempdata set message, because not possible set viewbag.
filtercontext.controller.tempdata["message"] = "access denied"; filtercontext.result = new httpunauthorizedresult();
the httpunauthorizedresult redirects me login action of account controller check (error)messages:
if (tempdata.count > 0) { var message = tempdata["message"]; modelstate.addmodelerror("", message.tostring()); }
Comments
Post a Comment