ASP.NET获取请求的url信息汇总
2024-09-12 11:10:16
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 时的日志输出结果:
分类总结一下:
获得完全路径(在浏览器中地址栏的url):Request.Url、Request.Url.AbsoluteUri、Request.Url.OriginalString
相对网站的虚拟路径(带请求参数):Request.Url.RawUrl、Request.Url.PathAndQuery
相对网站的虚拟路径(不带请求参数):Request.FilePath、Request.Path、Request.Url.AbsolutePath、Request.Url.LocalPath
仅获取请求参数信息:Request.Url.Query
最新文章
- 从零开始编写自己的C#框架(17)——Web层后端首页
- CompiledEffect Direct3D9 Sample fxc.exe
- this Activity.this Activity.class
- ubuntu14.04完全卸载mysql
- JS开发windows phone8.1系列之1
- JMeter学习(五)检查点
- 解决svn的working copy locked并且cleanup恢复不能的情况
- jBox 弹出窗口中焦点设置问题
- short a = 128, byte b = (byte)a 强制类型转换
- Json之语法,格式
- 用AS3清空容器下所有子显示对象
- bzoj 3566: [SHOI2014]概率充电器
- C# Hook原理及EasyHook简易教程
- WIP 投料报 Invalid Serial Number
- idea创建第一个普通java web项目
- CSS修改滚动条样式
- (免费电影)苹果手机合并.ts视频
- @RequestParam加不加的区别
- serlvet中的过滤器filter
- Python——字符串2.0(实验)(python programming)
热门文章
- cocos在win平台exe无法使用 UserDefault 解决方法
- 清除SQL数据库的日志
- maven pox.xml 设置主入口配置节点
- Membership三步曲
- [Python] Magic editor in Pycharm
- Fiddler进行手机抓包
- Android 学习笔记之网络通信基础+WebView....
- Qt之QAbstractItemView视图项拖拽(一)
- Java集合框架源码剖析:LinkedHashSet 和 LinkedHashMap
- idea上实现github代码同步