当前位置: 移动技术网 > IT编程>开发语言>.net > Asp.net中Request.Url的各个属性对应的意义介绍

Asp.net中Request.Url的各个属性对应的意义介绍

2017年12月12日  | 移动技术网IT编程  | 我要评论

旺角十二金钗,高中艺术学校,史上最强弟子兼一50

1.简单的环境搭建
  在本地iis上配置了一个网站:主机名为wjnhome.com,端口88,然后建了一个虚拟目录指向同一站点,虚拟目录名称为virtual,配置host为127.0.0.1  wjnhome.com
  所以地址就为:http://jb51.net:88/virtual/urldemo.aspx?id=2#top
2.编写简单的代码
复制代码 代码如下:

//虚拟目录的路径
response.write("<strong>request.applicationpath:</strong>" + request.applicationpath + "</br>");
//站点的物理路径(完整路径)
response.write("<strong>request.physicalpath:</strong>" + request.physicalpath + "</br>");
//站点物理路径的目录
response.write("<strong>directoryname:</strong>" + system.io.path.getdirectoryname(request.physicalpath) + "</br>");
//站点物理路径的目录
response.write("<strong>request.physicalapplicationpath:</strong>" + request.physicalapplicationpath + "</br>");
//当前页面的文件名
response.write("<strong>filename:</strong>" + system.io.path.getfilename(request.physicalpath) + "</br>");
//当前页面的虚拟路径
response.write("<strong>request.currentexecutionfilepath:</strong>" + request.currentexecutionfilepath + "</br>");
//当前页面的虚拟路径
response.write("<strong>request.filepath:</strong>" + request.filepath + "</br>");
response.write("<strong>request.path:</strong>" + request.path + "</br>");
//原始url
response.write("<strong>request.rawurl:</strong>" + request.rawurl + "</br>");
//绝对路径(不包括参数什么的)
response.write("<strong>request.url.absolutepath:</strong>" + request.url.absolutepath + "</br>");
//绝对url
response.write("<strong>request.url.absoluteuri:</strong>" + request.url.absoluteuri + "</br>");
//url协议方案
response.write("<strong>request.url.scheme:</strong>" + request.url.scheme + "</br>");
//url的主机名
response.write("<strong>request.url.host:</strong>" + request.url.host + "</br>");
//url端口号
response.write("<strong>request.url.port:</strong>" + request.url.port + "</br>");
//主机名+端口号
response.write("<strong>request.url.authority:</strong>" + request.url.authority + "</br>");
//获取文件名的本地操作系统表现形式
response.write("<strong>request.url.localpath:</strong>" + request.url.localpath + "</br>");
//附加路径信息,例如http://jb51.net:88/urldemo.aspx/hello?id=22#top 那么这里就是hello
response.write("<strong>request.pathinfo:</strong>" + request.pathinfo + "</br>");
//url的路径和get参数
response.write("<strong>request.url.pathandquery:</strong>" + request.url.pathandquery + "</br>");
//url的get参数
response.write("<strong>request.url.query:</strong>" + request.url.query + "</br>");
//主要指的是http://jb51.net:88/urldemo.aspx/hello?id=22#top中#后面的top。
//但一般情况下无法获取值,因为浏览器不会把这个值发送到服务器端
response.write("<strong>request.url.fragment:</strong>" + request.url.fragment + "</br>");
//主机名
response.write("<strong>request.url.dnssafehost:</strong>" + request.url.dnssafehost + "</br>");
//url的全部
response.write("<strong>request.url.originalstring:</strong>" + request.url.originalstring + "</br>");
//这种情况 uri uriaddress = new uri ("http://user:password@www.contoso.com/index.htm ") console.writeline(uriaddress.userinfo);
response.write("<strong>request.url.userinfo:</strong>" + request.url.userinfo + "</br>");
//从某个页面跳转过来的时候会显示源页面的值
response.write("<strong>request.urlreferrer:</strong>" + request.urlreferrer + "</br>");
//uri的每一段
for (var i = 0; i < request.url.segments.length;i++ )
{
response.write("<strong>request.url.segment" + i + ":</strong>" + request.url.segments[i] + "</br>");
}

3.输出结果
  request.applicationpath:/virtual
  request.physicalpath:e:\vsproject\201200420\urldemo\urldemo\urldemo.aspx
  directoryname:e:\vsproject\201200420\urldemo\urldemo
  request.physicalapplicationpath:e:\vsproject\201200420\urldemo\urldemo\
  filename:urldemo.aspx
  request.currentexecutionfilepath:/virtual/urldemo.aspx
  request.filepath:/virtual/urldemo.aspx
  request.path:/virtual/urldemo.aspx
  request.rawurl:/virtual/urldemo.aspx?id=2
  request.url.absolutepath:/virtual/urldemo.aspx
  request.url.absoluteuri:http://jb51.net:88/virtual/urldemo.aspx?id=2
  request.url.scheme:http
  request.url.host:wjnhome.com
  request.url.port:88
  request.url.authority:wjnhome.com:88
  request.url.localpath:/virtual/urldemo.aspx
  request.pathinfo:
  request.url.pathandquery:/virtual/urldemo.aspx?id=2
  request.url.query:?id=2
  request.url.fragment:
  request.url.dnssafehost:wjnhome.com
  request.url.originalstring:http://jb51.net:88/virtual/urldemo.aspx?id=2
  request.url.userinfo:
  request.urlreferrer:
  request.url.segment0:/
  request.url.segment1:virtual/
  request.url.segment2:urldemo.aspx

作者:wjn

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网