asp.net(C#)服务器绝对路径转换成URL相对路径[修改]

来源:互联网 发布:c语言中sleep函数单位 编辑:程序博客网 时间:2024/06/15 17:06




//本地路径转换成URL相对路径
     private string urlconvertor(string imagesurl1)
    
{
        
string tmpRootDir = Server.MapPath(System.Web.HttpContext.Current.Request.ApplicationPath.ToString());//获取程序根目录
        string imagesurl2 = imagesurl1.Replace(tmpRootDir, ""); //转换成相对路径
        imagesurl2 = imagesurl2.Replace(@"\"@"/");
        
//imagesurl2 = imagesurl2.Replace(@"Aspx_Uc/", @"");
        return imagesurl2;
    }

    
//相对路径转换成服务器本地物理路径
    private string urlconvertorlocal(string imagesurl1)
    
{
        
string tmpRootDir = Server.MapPath(System.Web.HttpContext.Current.Request.ApplicationPath.ToString());//获取程序根目录
        string imagesurl2 = tmpRootDir + imagesurl1.Replace(@"/"@"\"); //转换成绝对路径
         return imagesurl2;
    }