通过Request对象获取asp.net页面的URL信息
发布:智码IT网 阅读:
比如地址栏录入的URL为:https://localhost:44331/test/WebForm3.aspx?id=1&page=1,则Request对象的常见用法值如下:
//ToString()方法
var s = Request.Url.ToString();
//结果为: https://localhost:44331/test/WebForm3.aspx?id=1&page=1
//AbsoluteUri
var s = Request.Url.AbsoluteUri;
//结果为: https://localhost:44331/test/WebForm3.aspx?id=1&page=1
//主机名 Host(域名)
var s = Request.Url.Host;
// 结果为: localhost
//Authority(域名和端口号)
var s = Request.Url.Authority;
//结果为:localhost:44331
//端口Port
var s = Request.Url.Port;
//结果为:44331
//绝对路径 AbsolutePath
var s = Request.Url.AbsolutePath;
//结果为: /test/WebForm3.aspx
//参数信息 Query
var s = Request.Url.Query;
//结果为:?id=1&page=1
//路径和参数 PathAndQuery
var s = Request.Url.PathAndQuery;
//结果为: /test/WebForm3.aspx?id=1&page=1
//RawUrl
var s = Request.RawUrl;
//结果为: /test/WebForm3.aspx?id=1&page=1