How do I specify a return url for a link to the login form?

后端 未结 4 2237
醉酒成梦
醉酒成梦 2021-01-31 12:35

Simple enough, it would seem, but it turns out not to be - mainly due to the fact that the View can\'t possibly know which way through Model and Controller you got there. Regard

4条回答
  •  北恋
    北恋 (楼主)
    2021-01-31 13:24

    One way would be to build the links that send the user to the login form, with returnUrl=/PageToReturnTo (Login for example). You'd want to write it so the return url was constructed from your routes though, manually writing those links on every page could be cumbersome.

    The default login action in MVC has the returnUrl functionality already built. Just need to pass it a value and it will do the rest. Here's a copy'n paste of the method signature from a fresh project.

    public ActionResult Login(string username, string password, bool rememberMe, string returnUrl)
    

    Hope that helps ya!

提交回复
热议问题