码迷,mamicode.com
首页 > Web开发 > 详细

ASP.NET获取请求的url信息汇总

时间:2015-06-08 21:32:34      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:

ASP.NET获取请求的url信息汇总

  最近做项目需要处理一个用代码获取当前网站的域名或ip信息的问题,于是尝试了ASP.NET中各种获取url信息的方法,在此总结一下:

在Global.asax文件中的 Application_BeginRequest 方法中,加入以下代码,利用日志文件记录各种方法得到的信息

            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 是定义的一个基于log4net的日志助手
技术分享

 Common.LogHelper 日志助手类 定义

技术分享

请求url为:http://localhost:13877/NewsList-18.aspx?t=1&s=1 时的日志输出结果:

技术分享

 

ASP.NET获取请求的url信息汇总

标签:

原文地址:http://www.cnblogs.com/ben121011/p/aspdotnetGetRequestUrlInfo.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!