当前位置:Gxlcms > asp.net > Asp.net中获取应用程序完整Url路径的小例子

Asp.net中获取应用程序完整Url路径的小例子

时间:2021-07-01 10:21:17 帮助过:7人阅读

代码如下:
/// <summary>
/// Gets the absolute root
/// </summary>
public static Uri AbsoluteWebRoot
{
    get  www.gxlcms.com
    {
        var context = HttpContext.Current;
        UriBuilder uri = new UriBuilder();
        uri.Host = context.Request.Url.Host;
        if (!context.Request.Url.IsDefaultPort)
        {
            uri.Port = context.Request.Url.Port;
        }

        uri.Path = VirtualPathUtility.ToAbsolute("~/");

        Uri absoluteWebRoot = uri.Uri;

        return absoluteWebRoot;
    }
}

人气教程排行