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

后端 未结 4 2254
醉酒成梦
醉酒成梦 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:17

    You can use Page.Request.Url to get the route that resulted in the currently rendered view.

    Though that's more of a cosmetic detail, you might want to unify the requests that came through the '/' and '/default.aspx' routes and always return to the '/' route. I have a helper property in my master page that does exactly that.

        protected Uri RouteUrl
        {
            get
            {
                if (Page.Request.Url.AbsolutePath.StartsWith("/default.aspx", StringComparison.OrdinalIgnoreCase))
                {
                    return new Uri(Request.Url, new Uri(Response.ApplyAppPathModifier("~/")));
                }
    
                return Page.Request.Url;
            }
        }
    

提交回复
热议问题