Again, I am new to MVC, so please be easy on me. When the session expires, I need to redirect the user to the login page. I found a way to do this by overloading the session ExpireFilterAttribute class, but my site was caught in a redirect loop. It is not enough to know about MVC, what is happening. Can someone explain a redirect loop to stop?
The main page I am using as a template, but I have also searched Staxwell Flow and have seen many pages including.
This page seems to be the closest to my problem, but I mentioned that solution (session session to take session accessifter for different controller), but he did not help me.
Here is a code Hold a session timeout This is in a file that is in a folder named FilterConfig.cs App_Start:
Public Category FilterConfig {Public Static Zero Register Global Filter (GlobalFilterCollection Filters) {filters.Add (New HandleErrorAttribute ()); Filter. Add (New Season ExpireFilterAttribute ()); }} Public class session ExpireFilterAttribute: Akshnfiltr Aetribet {public override void Onakshnakshiring (action Aksepting Contact Filter Kantaks) {Actiteepitiantititititisiaks = Actiteepisionekt. On; // Check if the session is supported (ctx session! = Null) {// Check that if a new session ID is generated (ctx.Session.IsNewSession) {// If it says it is a new Session, but if an existing session cookie is present, it should be // string session has expired cookie = ctx.Request.Headers ["cookie"]; (If (null! = Session cookie) & amp; (session cookies. Index ( "ASP. NET_SessionId")> gt; = 0 & amp; session cookies! = "Reset")) {ctx.Response.Redirect ( " ~ / Admin / log in "); }} Base.OnActionExecuting (filterContext); }}}
Then I have this code, which is called ErrorController.cs. I also tried to do this in AdminController.cs, but I took it to a different controller on the log method. Public class error controller: Administrator {[Sensexerfilter] Public ActionSecult Index 2 () {// This method will not execute that our session has expired / render Home page View refund (); }}
Then there is the login method. When this is the "Return View" part when it is in AdminController.cs, this session goes on ExpireFilterAttribute.
public proceedings login () (if (Session [ "AdminUserName"] = null) {redirect return ( "Index");} ModelAdminLogin obj_MAL = new ModelAdminLogin (); Session [ "Captcha "] = Claintatiliti. GenerateRandomCode (); session [" Arrom "] = null; if ((request. cookies [" ADMINUSERNAME "]! = null) & amp; amp; amp; and (requests. cookies [" Adminward "] = nULL)) {obj_MAL.UserName = ClientUtility.DecryptString (request. cookies [ "ADMINUSERNAME"] .Value); Obj_MAL.Password = ClientUtility.DecryptString (request. cookies [ "Adminford"]. value); Obj_MAL.RememberMe = true Return View (obj_MAL);} and { Exclamation view (obj_MAL);}}
To summarize, when a session expires, the site session calls ExpireFilterAttribute.OnActionExecuting (required) which see the redirected as admin / login (desired), but appears to the user before the page, this session ExpireFilterAttribute.OnActionExecuting start loop which then calls. finally, I get the error message "this site There is a redirect loop. " When a session is over, I need a way to redirect to the login page and after coming to the login screen it will not have to go back to the session-before filter attribute class.
I would appreciate it for any help. Thank you.
I suspect that you are also putting attribute on login action, which is causing the loop to login Use the Allow Allow
attribute on the Action:
[AllowAnonymous] Public Function Logins () {}
No comments:
Post a Comment