关于"未能映射路径"问题

来源:互联网 发布:手机淘宝网app下载 编辑:程序博客网 时间:2024/04/30 11:03

未能映射路径,在作页面生成时,老是出现"未能映射路径"/aa/bb/cc".

研究了半天,终于找出原因了,Server.Mapth(string path),path-->是相对路径。所以,改为Server.Mapth("aa/bb/cc")就好了,.net 会自动找"aa/bb/cc",返回相对路径。


//如果不存在,使用System.IO.Directory.CreateDirectory创建文件夹。

 if (!System.IO.Directory.Exists(System.Web.HttpContext.Current.Server.MapPath(path)))            {                System.IO.Directory.CreateDirectory(System.Web.HttpContext.Current.Server.MapPath(path));            }            System.IO.StreamWriter sw = new System.IO.StreamWriter(System.Web.HttpContext.Current.Server.MapPath(path + "/" + file), false, System.Text.Encoding.GetEncoding("gb2312"));            sw.Write(temp);


切记: Server.Mapth("相对路径").

解决方案一:将绝对路径/bin/WebSet.xml设为相对路径即可:~/aa/bb/WebSet.xml

解决方案二:使用System.Web.HttpContext.Current.Request.PhysicalApplicationPath+("/Bin/WebSet.xml");
其中System.Web.HttpContext.Current.Request.PhysicalApplicationPath表示的是项目的根目录。 

解决方案三:将/aa/bb/cc改为aa/bb/cc