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

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -