c# - Redirect to Login if not authenticated? -


i have application multiple modules under 1 domain. https://somedomain.es/

suppose have modules module1 , module2, can access modules as
https://somedomain.es/module1

https://somedomain.es/module2

when try access above url redirects me login page if not authenticated.where if try access pages inside module1 not redirect login page. rather tries serve response initializing controller. controller has constructor requires icustomprincipal parameter , injected using unity ioc. fails when resolving icustomprincipal since identity null.

https://somedomain.es/module1 (redirects login)

https://somedomain.es/module1/profile/2 (does not redirect login)

web.config:

 <authentication mode="forms">    <forms name=".somelogincookie" loginurl="~/account/login" timeout="2880" protection="all" enablecrossappredirects="true" />  </authentication> 

i use custom authorize attribute marked on controller

public class customauthorizeattribute : authorizeattribute {     public icustomprincipal customprincipal;      protected override bool authorizecore(httpcontextbase httpcontext)     {         bool authorize = false;         authorize = base.authorizecore(httpcontext);          if(!authorize)             return false;          if(!httpcontext.request.isauthenticated)             return false;          if(customprincipal== null)         {             var factory = new principalfactory(httpcontext.user);             customprincipal= factory.createprincipal();         }          if(customprincipal.haspermissions(function))             authorize = true;         else             authorize = false;          return authorize;     }      protected override void handleunauthorizedrequest(authorizationcontext filtercontext)     {         if(filtercontext.httpcontext.request != null && filtercontext.httpcontext.request.isauthenticated)         {             filtercontext.result = new viewresult() { viewname = "accessdenied" };                 //new httpstatuscoderesult(403);         }         else         {             base.handleunauthorizedrequest(filtercontext);         }     } 

i have tested using [authorize] attribute instead of custom 1 no success.

i'm not sure issue here. please share thoughts.

controller:

[nocache] [customauthorize(customfunction.profile)] public partial class profilecontroller : controller {     public icustomprincipal principal {get; set;}      public profilecontroller(icustomprincipal principal)     {         principal = principal;     }      public actionresult index(int id)     {     } } 

this case on timeout too.

when use form authentication set authentication cookie method:

formsauthentication.setauthcookie 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -