ASP. NET obtains the summary of the requested url Information and asp. neturl information.

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.