日期:2014-05-17  浏览次数:21106 次

Asp.net中获取应用程序完整Url路径的方法

查看原文


/// <summary>
/// Gets the absolute root
/// </summary>
public static Uri AbsoluteWebRoot
{
    get
    {
        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;
    }
}