处理函数如下:    // 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));
    }
调用时:    public static string ToProduct(string productId)
    {
        return BuildAbsolute(String.Format("Product.aspx?ProductID={0}", productId));
    }
为什么要这样处理呢?

解决方案 »

  1.   

    相对的,找文件和执行文件操作等.是找不到的只有绝对才可行.上面你代码中转换,为避免出错,因为是布署时,可能直接IID中建立网站,也可能在已有网站下建立虚拟目录
      

  2.   

    还有可能,IIS中,建立时,设置有端口号.
      

  3.   

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

  4.   

    以为了以后发布方便,如果路径写死了C:\xxx\xxx\imge\xxx.jpg。你想象一下,以后玩意要发布的到D盘怎么办?
      

  5.   

    绝对路径:是从盘符开始的路径,形如:C:\windows\system32\cmd.exe
    相对路径:是指当前所在的目录路径 .\system32\cmd.exe