1
你好,我建立一個WCF Web服務,它應該返回我網站的根頁面。 例子:如何找到ASP.NET中的根頁面?
Webservice的地址:
http://localhost/bov2/OPS.svc
根頁:
http://localhost/bov2/
如何創建一個字符串,它顯示我的根頁?
在此先感謝您的幫助
你好,我建立一個WCF Web服務,它應該返回我網站的根頁面。 例子:如何找到ASP.NET中的根頁面?
Webservice的地址:
http://localhost/bov2/OPS.svc
根頁:
http://localhost/bov2/
如何創建一個字符串,它顯示我的根頁?
在此先感謝您的幫助
試試這個
string baseUrl = String.Format("{0}://{1}{2}/", Request.Url.Scheme,
Request.Url.Authority,
Request.ApplicationPath.TrimEnd('/'));
有時候,我把它放在一個公共類,在這種情況下,你應該使用這個語法
public static string GetBaseUrl()
{
HttpContext context = HttpContext.Current;
string baseUrl = String.Format("{0}://{1}{2}/",
context.Request.Url.Scheme,
context.Request.Url.Authority,
context.Request.ApplicationPath.TrimEnd('/'));
return baseUrl;
}
哇這麼快,非常感謝你 –
它對你有用嗎? – Silagy
它在網站上工作,但不在我的web服務上,它無法找到「請求」。 –