public static string GetBaseURL()
{
if (HttpContext.Current.Request.ApplicationPath == "/")
{
return @"http://" + HttpContext.Current.Request.Url.Host;
}
else
{
return @"http://" + HttpContext.Current.Request.Url.Host + HttpContext.Current.Request.ApplicationPath;
}
}
{
if (HttpContext.Current.Request.ApplicationPath == "/")
{
return @"http://" + HttpContext.Current.Request.Url.Host;
}
else
{
return @"http://" + HttpContext.Current.Request.Url.Host + HttpContext.Current.Request.ApplicationPath;
}
}
本文介绍了一种在ASP.NET环境中获取当前应用程序基础URL的方法。该方法检查ApplicationPath来确定是否处于根目录,并据此构建完整的URL。这对于需要动态生成链接或进行外部调用的场景非常有用。
110

被折叠的 条评论
为什么被折叠?



