程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> ASP.NET >> ASP.NET基礎 >> Asp.net中Request.Url的各個屬性對應的意義介紹

Asp.net中Request.Url的各個屬性對應的意義介紹

編輯:ASP.NET基礎
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:[email protected]/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
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved