2014-05-21 56 views
0

On on aspx.page關於後面的代碼,我想要另一個網頁的完整URI!有一些標準功能!獲取網頁的完整url

所以說,我是在

http:\\test.us\dir1\link1.aspx 

在這個頁面,我想基於相對URL

GetFullUri( 「〜\ DIR2 \ link2.aspx」),以獲得完整的URI

然後返回是

的http:\ test.us \ DIR2 \ link2.aspx

回答

2

您可以編寫一個函數,它將相對路徑輸入,然後根據當前的URL返回完整路徑。不要通過〜作爲rel中的方法

 URL used for this example: 
     http://localhost:12345/site/page.aspx?q1=1&q2=2 

     Value of HttpContext.Current.Request.Url.Host 
     localhost 

     Value of HttpContext.Current.Request.Url.Authority 
     localhost:12345 

     Value of HttpContext.Current.Request.Url.AbsolutePath 
     /site/page.aspx 

     Value of HttpContext.Current.Request.ApplicationPath 
     /site 

     Value of HttpContext.Current.Request.Url.AbsoluteUri 
     http://localhost:12345/site/page.aspx?q1=1&q2=2 

     static string (HttpContext context , string rel) 
     { 
      return HttpContext.Current.Request.Url.Scheme + "://" HttpContext.Current.Request.Url.Authority + rel; 
     } 
+0

謝謝你的回覆!爲什麼我不能通過〜 – lordkain

+0

〜不是你需要的URL的一部分。 – Devesh