2012-05-12 58 views
0

使用Ajax時我參觀Request.Url當MVC使用AJAX,網址會添加一些標籤,如:訪問Request.Url當MVC

www.test.com/home/index/4?X -Requested-With = XMLHttpRequest

如何獲得實際的網址或如何刪除標籤沒有任何硬編碼?

回答

0

你可以使用:

string url = Request.Url.AbsolutePath; // should give you /home/index/4 

,如果你想要一個絕對URL,你可以試試:

var builder = new UriBuilder(Request.Url); 
builder.Query = string.Empty; 
string url = builder.ToString(); // should give you http://www.test.com/home/index/4