日期:2014-05-20  浏览次数:20426 次

ASP.NET 中为什么要把相对路径处理成 绝对路径
处理函数如下:
C# code

    // Builds an absolute URL
    private static string BuildAbsolute(string relativeUri)
    {
        // get current uri
        Uri uri = HttpContext.Current.Request.Url;
        // build absolute path
        string app = HttpContext.Current.Request.ApplicationPath;
        if (!app.EndsWith("/")) app += "/";
        relativeUri = relativeUri.TrimStart('/');
        // return the absolute path
        return HttpUtility.UrlPathEncode(
          String.Format("http://{0}:{1}{2}{3}",
          uri.Host, uri.Port, app, relativeUri));
    }



调用时:
C# code

    public static string ToProduct(string productId)
    {
        return BuildAbsolute(String.Format("Product.aspx?ProductID={0}", productId));
    }



为什么要这样处理呢?

------解决方案--------------------
相对路径处理成 绝对路径 ?
我估计你看反了。。。
比如image/a.jpg. 处理成绝对路径以后是不是C:/users/Yamat/China/Csdn/images/image/a.jpg.
然后把项目上传服务器。图片就是个X。