2011年2月12日

asp.net 取得專案執行Root的URL

web form任一頁面例如「http://localhost:3586/CarbonPlatform/ZZZ/DefTest.aspx?id=1」
目標取得「http://localhost:3586/CarbonPlatform/」web project的root所在之URL

似乎沒有直接用內建函式取到的方法?

不過若可做出一個extraUrl是「ZZZ/DefTest.aspx」, 便可remove掉取得想要的字串了..
Request.Url.AbsoluteUri
ex.「http://localhost:3586/CarbonPlatform/ZZZ/DefTest.aspx?id=1」
Request.Url.AbsoluteUri.IndexOf(extraUrl)
ex.「37」
Request.Url.AbsoluteUri.Remove(Request.Url.AbsoluteUri.IndexOf(extraUrl))
ex.「http://localhost:3586/CarbonPlatform/」