Example:
public partial class Login : Page { public string RootUrl { get { Uri requestUri = Context.Request.Url; HttpRequest request = Context.Request; string rootUrl = string.Format("{0}{1}{2}{3}{4}", requestUri.Scheme, Uri.SchemeDelimiter, requestUri.Host, requestUri.IsDefaultPort ? string.Empty : string.Format(":{0}", requestUri.Port), request.ApplicationPath); return rootUrl.EndsWith("/") ? rootUrl : string.Format("{0}/", rootUrl); } } protected override void OnLoad(EventArgs e) { base.OnLoad(e); string returnUrl = this.Request.QueryString.Get("ReturnUrl"); if (!string.IsNullOrEmpty(returnUrl)) { if (!returnUrl.ToLower().Contains("http://")) { returnUrl = Path.Combine(this.RootUrl, returnUrl); string url = string.Format("{0}?ReturnUrl={1}", this.Request.Path, Server.UrlEncode(returnUrl)); this.Response.Redirect(url); } } } }Referene
No comments:
Post a Comment