ASP. NET Get URL Method Summary

  • 2021-07-18 07:50:06
  • OfStack

//Get the full url (protocol name + domain name + site name + file name + parameters)

string fullUrl = Request.Url.ToString();

//Get URL information requested by the client (excluding host and port)

string rawUrl = Request.RawUrl;

//Get site name + page name

string absolutePath = Request.Url.AbsolutePath;

//Get the host part

string urlHost = Request.Url.Host;

//Get Parameters section

string urlQuery = Request.Url.Query;

//Get the virtual path of the ASP. NET application on the server

string ApplicationPath = Request.ApplicationPath;

//Get the virtual path of the current request

string CurrentExecutionFilePath = Request.CurrentExecutionFilePath;

//Get the virtual path of the current request

string Path = Request.Path;

//Get additional path information for a resource with an URL extension

string PathInfo = Request.PathInfo;

//Get the physical file system path corresponding to the requested URL

string PhysicalPath = Request.PhysicalPath;

//Get the local operating system representation of the file name

string LocalPath = Request.Url.LocalPath;

//Get absolute URL

string AbsoluteUri = Request.Url.AbsoluteUri;

Complete code demonstration


StringBuilder sb = new StringBuilder();
sb.Append(" Get the complete url (Protocol name + Domain name + Site name + Filename + Parameter) :" + fullUrl + "<br />");
sb.Append(" Object requested by the client URL Information (excluding hosts and ports) :" + rawUrl + "<br />");
sb.Append(" Get the site name + Page name :" + absolutePath + "<br />");
sb.Append(" Get the host part :" + urlHost + "<br />");
sb.Append(" Get Parameters Section :" + urlQuery + "<br />");
sb.Append(" Gets the virtual application root path of the application :" + ApplicationPath + "<br />");
sb.Append(" Gets the virtual path of the current request :" + Path + "<br />");
sb.Append(" Gets a URL Additional path information for resources with extension :" + PathInfo + "<br />");
sb.Append(" Objects associated with the requested URL Corresponding physical file system path :" + PhysicalPath + "<br />");
sb.Append(" Gets the local operating system representation of the file name :" + LocalPath + "<br />");
sb.Append(" Get absolute URL:" + AbsoluteUri + "<br />");
Response.Write(sb.ToString());


Related articles: