C# ashx页面获取URL参数
后台获取代码
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
context.Response.Write("Hello World");
// 当前页面完整URL为:http://www.hicsharp.com/index.ashx?keyword=test&page=1
// 1.获取页面完整的URL,协议名+域名+站点名+文件名+参数
string url = context.Request.Url.ToString();
// 结果:http://www.hicsharp.com/index.ashx?keyword=test&page=1
// 2.获取页面完整的URL,协议名+域名+站点名+文件名+参数
string absoluteUri = context.Request.Url.AbsoluteUri;
// 结果:http://www.hicsharp.com/index.ashx?keyword=test&page=1
// 3.获取域名或主机,不包含端口
string host = context.Request.Url.Host;
// 结果:www.hicsharp.com
// 4.获取域名或主机, 包含端口, 如果端口默认是80则不显示
string authority = context.Request.Url.Authority;
// 结果:www.hicsharp.com:8080
// 5.获取请求页面
string pathAndQuery = context.Request.Url.PathAndQuery;
// 结果:/index.ashx?keyword=test&page=1
// 6.获取请求页面的真实地址, 如果使用伪静态, 可以获取伪静态指向的页面
// http://www.hicsharp.com/article/123.html
// http://www.hicsharp.com/article/details.ashx?id=123
string rawUrl = context.Request.RawUrl.ToString();
// 结果:/article/123.html
// 7.获取请求参数
string query = context.Request.Url.Query;
// 结果:?keyword=test&page=1
}