2012-09-11 45 views
0

我有幾種不同的路徑安裝。主文件夾的url

FE:

  1. http://Somepath.xx/
  2. http://Someotherpath.xy/Maincontent/

問題是,如何dynamycly檢測的路徑?

我找到辦法如何爲第一種情況下做到這一點:

Request.Url.Scheme + System.Uri.SchemeDelimiter + Request.Url.Host + (Request.Url.Port != 80 ? ":" + Request.Url.Port : "") 

但如何爲第二次做到這一點,或一般用於更復雜的例子......我不知道。

我需要在控制器一樣查看

回答

0

你可以使用Url.Content方法:

string root = Url.Content("~/"); 

網址助手是在兩個控制器和視圖可用。

+0

它只返回「/」 –

+0

你想要一個絕對的網址嗎? –

+0

是的,像http://Someotherpath.xy/Maincontent/ –

0

你可以看一下Server.MapPath功能和查看示例及其工作here

希望這有助於非正式解釋。