ASP.NET MVC Login ReturnUrl always NULL?

后端 未结 5 2337
死守一世寂寞
死守一世寂寞 2020-12-08 06:15

Using Forms Authentication in ASP.NET MVC when trying to log back into a site, it puts a ReturnUrl parameter in the query string. My Logon action method accepts a \"returnU

5条回答
  •  时光说笑
    2020-12-08 06:36

    There are two ways I can think of to deal with logon and logoff scenarios. Dave Beer outlined one way, above. There is another approach that works in many situations. I used it when I coded the NerdDinner tutorial. The tutorial provides us with a logoff function that logs you off and takes you home. I did not want that. I wanted to return to the page I was on before I logged off. So I modified my Account controller logoff action to look like this

       public ActionResult LogOff()
        {
            FormsService.SignOut();
            return Redirect(Request.UrlReferrer.ToString());
        }
    

    You can get fancier and pass in a returnUrl and test for it, in case you want to override this behavior. But I don't need that. This achieves the desired result. The Logon can work similarly. Maybe there are ways to use the MVC framework to do this for me, but until I learn them, this is VERY simple and works reliably.

提交回复
热议问题