1. 程式人生 > >【轉】MVC中Controller獲取當前View的URL

【轉】MVC中Controller獲取當前View的URL

ASP.NET通用: 

【1】獲取完整url (協議名+域名+虛擬目錄名+檔名+引數) 

string url=Request.Url.ToString();

【2】獲取 虛擬目錄名+頁面名+引數: 

string url=Request.RawUrl;

(或 string url=Request.Url.PathAndQuery;)

【3】獲取 虛擬目錄名+頁面名:

string url=HttpContext.Current.Request.Url.AbsolutePath;

(或 string url= HttpContext.Current.Request.Path;)

【4】獲取 域名:

string url=HttpContext.Current.Request.Url.Host;

【5】獲取 引數: 

string url= HttpContext.Current.Request.Url.Query; 

【6】獲取 埠:

Request.Url.Port