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

后端 未结 4 2488
醉酒成梦
醉酒成梦 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条回答
  •  猫巷女王i
    2021-01-31 13:24

    The solution is to use HttpContext.Current.Request.RawUrl like this:

    <%= Html.ActionLink("log on", "LogIn", new { controller = "User", returnUrl = HttpContext.Current.Request.RawUrl }) %>
    

    Or with an extension method from MVC futures (Microsoft.Web.Mvc.dll):

    <%= Html.ActionLink(c => c.LogOn("name", "password", false, HttpContext.Current.Request.RawUrl), "login here")%>
    

    ActionController is the default one in mvc but just add returnUrl to your own.

提交回复
热议问题