- 打卡等级:即来则安
- 打卡总天数:29
- 打卡月天数:1
- 打卡总奖励:7791
- 最近打卡:2025-12-13 17:25:16
管理员
- 积分
- 21301
|
后台获取代码
- // 当前页面完整URL为:http://www.hicsharp.com/index.aspx?keyword=test&page=1
-
- // 1.获取页面完整的URL,协议名+域名+站点名+文件名+参数
- string url = Request.Url.ToString() ;
- // 结果:http://www.hicsharp.com/index.aspx?keyword=test&page=1
-
- // 2.获取页面完整的URL,协议名+域名+站点名+文件名+参数
- string absoluteUri = Request.Url.AbsoluteUri;
- // 结果:http://www.hicsharp.com/index.aspx?keyword=test&page=1
-
- // 3.获取域名或主机,不包含端口
- string host = Request.Url.Host;
- // 结果:www.hicsharp.com
-
- // 4.获取域名或主机, 包含端口, 如果端口默认是80则不显示
- string authority = Request.Url.Authority;
- // 结果:www.hicsharp.com:8080
-
- // 5.获取请求页面
- string pathAndQuery = Request.Url.PathAndQuery;
- // 结果:/index.aspx?keyword=test&page=1
-
- // 6.获取请求页面的真实地址, 如果使用伪静态, 可以获取伪静态指向的页面
- // http://www.hicsharp.com/article/123.html
- // http://www.hicsharp.com/article/details.aspx?id=123
- string rawUrl = Request.RawUrl.ToString();
- // 结果:/article/123.html
-
- // 7.获取请求参数
- string query = HttpContext.Current.Request.Url.Query;
- // 结果:?keyword=test&page=1
复制代码 其他一些常用参数获取
获取请求页面Request.RawUrl: --> "/index.aspx"获取服务器上ASP.NET应用程序的虚拟路径Request.ApplicationPath: --> "/"获取当前请求的虚拟路径Request.CurrentExecutionFilePath: --> "/index.aspx"获取当前请求的路径Request.Path: --> "/index.aspx"获取服务器上的物理文件系统路径Request.PhysicalPath: --> "d:\wwwroot\demo\index.aspx"获取请求完整URLRequest.Url.AbsoluteUri: --> "http://localhost:8080/index.aspx"获取请求完整页面Request.Url.AbsolutePath: --> "/index.aspx" 来源:C#社区
原文:https://www.hicsharp.com/a/0eb235de3da840a6b3e8d491b129a516
|
|