2014-03-27 55 views
1

當前我試圖獲取瀏覽器中顯示的當前URL。獲取瀏覽器中顯示的當前URL

如果我使用

Request.Path 

我得到https://this.website.com:443/Default.aspx這在技術上是正確的。

但是瀏覽器本身顯示的URL是https://this.website.com/

使用任何請求選項仍然會顯示Default.aspx。

我需要最終檢測瀏覽器的URL是否爲https://this.website.comhttp://this.website.com/Default.aspx,然後重定向到Default.aspx,如果它不存在。

Btw使事情變得更復雜是我的web.config中的https重定向。

+0

的重複[如何獲得當前頁面的C#中的URL](http://stackoverflow.com/questions/593709/how-to-get-the-url-of-the-current- page-in-c-sharp) –

+1

這不是一個重複的問題。我想弄清楚的是如何區分http://www.site.com/和http://www.site.com/Default.aspx的區別。這顯然是asp.net決定是相同的。 – Prescient

回答

2

你可以從httpcontext中的請求中獲得它。

HttpContext.Current.Request.Url 

更新時間:

如果你想告訴羯羊當前網址是/或/default.aspx。您可以使用請求的RawUrl屬性。該字段將包含整個網址。

HttpContext.Current.Request.RawUrl 
+0

當瀏覽器窗口中的網址爲https://this.website.com/ – Prescient

+0

時,它不會啓動https://this.website.com/default.aspx您必須使用'HttpContext.Current.Request。 Url.Host' –

+0

@DanielB Nope。那只是給了我主機。我需要找出網址是否是this.site.com/或this.site.com/Default.aspx。 – Prescient