Asp.Net Absolute Path of a URL

∥☆過路亽.° 提交于 2019-12-02 14:12:08
John Rasch

I have used this in the past:

// Gets the base url in the following format: 
// "http(s)://domain(:port)/AppPath"
HttpContext.Current.Request.Url.Scheme 
    + "://"
    + HttpContext.Current.Request.Url.Authority 
    + HttpContext.Current.Request.ApplicationPath;

Old post but here is another slightly less verbose method

var baseUri = new Uri(HttpContext.Current.Request.Url, "/");
Waqi

I have used following and it worked for me both client and the server.

string surl = string.Format("{0}://{1}",
    HttpContext.Current.Request.Url.Scheme,
    HttpContext.Current.Request.Url.Authority);
user799577

Code :

string loginUrl = Request.Url.GetLeftPart(UriPartial.Authority) + VirtualPathUtility.ToAbsolute("~/") + "Login/Login.aspx?UserName=" + LoggedinUser["UserName"] + "&Password=" + LoggedinUser["Password"];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!