c# - .Net MVC 4 using Windows Authentication - redirect unauthorized user -


i have mvc 4 intranet app created using visual studio 2012. used windowsauthentication , authenticates users expected. on actions restricted users roles using authorize attribute. when user clicks on link invokes controller action user has no authorization pops 'authentication required' dialogue. when login account has no authorization keeps on popping dialogue. instead this:

  1. when user not authorized access page, pop dialogue doing.
  2. when user inputs login valid not authorized access page redirect page saying access forbidden.

how go doing this? relevant information customized role provider using approach discussed here

for need custom authorization handle unauthorized situations yourself.

you need method this:

[attributeusage(attributetargets.class | attributetargets.method, inherited = true, allowmultiple = true)] public class authorizeattribute : system.web.mvc.authorizeattribute {     protected override void handleunauthorizedrequest(system.web.mvc.authorizationcontext filtercontext)     {         if (filtercontext.httpcontext.request.isauthenticated)         {             filtercontext.result = new system.web.mvc.httpstatuscoderesult((int)system.net.httpstatuscode.forbidden);         }         else         {             base.handleunauthorizedrequest(filtercontext);         }     } } 

Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -