Asp.Netでアプリケーションの完全なUrlパスを取得する小さな例

725 ワード

 
  
///
/// Gets the absolute root
///

public static Uri AbsoluteWebRoot
{
    get  www.jb51.net
    {
        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;
    }
}