ASP. NET obtains the summary of the requested url Information and asp. neturl information.
Summary of url Information obtained by ASP. NET
Recently, a project needs to deal with the problem of getting the domain name or ip information of the current website using code. So I tried various methods in ASP. NET to obtain url Information. Here I will summarize:
In the Global. asax fileApplication_BeginRequest Method, add the following code to use the log file to record information obtained by various methods
HttpApplication app = sender as HttpApplication; logger.Debug("Request.ApplicationPath:" + app.Request.ApplicationPath); logger.Debug("Request.FilePath:" + app.Request.FilePath); logger.Debug("Request.Path:" + app.Request.Path); logger.Debug("Request.PathInfo:" + app.Request.PathInfo); logger.Debug("Request.PhysicalApplicationPath:" + app.Request.PhysicalApplicationPath); logger.Debug("Request.PhysicalPath:" + app.Request.PhysicalPath); logger.Debug("Request.RawUrl:" + app.Request.RawUrl); logger.Debug("Request.Url:" + app.Request.Url); logger.Debug("Request.Url.AbsolutePath:" + app.Request.Url.AbsolutePath); logger.Debug("Request.Url.AbsoluteUri:" + app.Request.Url.AbsoluteUri); logger.Debug("Request.Url.Authority:"+app.Request.Url.Authority); logger.Debug("Request.Url.Fragment:" + app.Request.Url.Fragment); logger.Debug("Request.Url.Host:" + app.Request.Url.Host); logger.Debug("Request.Url.LocalPath:" + app.Request.Url.LocalPath); logger.Debug("Request.Url.OriginalString:" + app.Request.Url.OriginalString); logger.Debug("Request.Url.PathAndQuery:" + app.Request.Url.PathAndQuery); logger.Debug("Request.Url.Query:" + app.Request.Url.Query); logger.Debug("Request.Url.Segments:"); foreach (string item in app.Request.Url.Segments) { logger.Debug(item+"\t"); }
Logger is a defined log Assistant Based on log4net.
Common. LogHelper log Assistant class definition
Request url: http: // localhost: 13877/NewsList-18.aspx? Result of log output when t = 1 & s = 1:
Summary:
Obtain the full path (url in the address bar of the browser): Request. Url, Request. Url. AbsoluteUri, Request. Url. OriginalString
Relative to the website's virtual path (with Request parameters): Request. Url. RawUrl, Request. Url. PathAndQuery
Relative to the website's virtual Path (without Request parameters): Request. FilePath, Request. Path, Request. Url. AbsolutePath, Request. Url. LocalPath
Retrieve Request parameter information only: Request. Url. Query