C# 如何在ASP.NET中查找根页面?
你好,我建立了一个WCF网站服务,它应该返回我的网站根页面。 例如: 网络服务地址:C# 如何在ASP.NET中查找根页面?,c#,asp.net,wcf,web-services,uri,C#,Asp.net,Wcf,Web Services,Uri,你好,我建立了一个WCF网站服务,它应该返回我的网站根页面。 例如: 网络服务地址: http://localhost/bov2/OPS.svc 根页面: http://localhost/bov2/ 如何创建显示根页面的字符串 提前感谢您的帮助试试这个 string baseUrl = String.Format("{0}://{1}{2}/", Request.Url.Scheme, Request.Url.Authority, Request.ApplicationPath.TrimE
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;
}
它在网站上工作,但在我的Web服务上不工作,它找不到“请求”。它工作。我只是用以下内容替换了httpcontext:httpcontext current=httpcontext.current;我建议重写为
string baseUrl=string.Format(“{0}://{1}{2}/”,Request.Url.Scheme,Request.Url.Authority Request.ApplicationPath.TrimEnd('/')代码>