怎么解决未能映射路径问题

发布时间:2019-07-31 10:44:34

异常详细信息: System.InvalidOperationException: 未能映射路径“/App_GlobalResources/”。

推荐回答

.net 相对路径请用:~/aa/bb 或者aa/bb。如果是html控件请不要用:~ 

win7或者vista的话,有些操作可能涉及到权限,使用管理员账号试试:右击我电脑-管理-本地用户和组-用户-administrations-右击选属性,将administrations禁用的勾去掉,再注销就可以看到administrations用户了。

Inherits="", 应该是 命名空间.类名

Server.Mapth(string path),path-->是相对路径。所以,改为Server.Mapth("aa/bb/cc")就好了,.net 会自动找"aa/bb/cc",返回相对路径。

 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);

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

切记: 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/WebSet.xml

////////----->

写一段读写文件的程序,使用System.Web.HttpContext.Current.Server.MapPath("/bin/WebSet.xml") ,不料却出现“未能映射路径”的错误,马上检查程序,感觉没有什么错误,于是乎网上搜, 找啊找,就是找不到解决方案。只有自己慢慢调试了。

 

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

解决方案二:使用System.Web.HttpContext.Current.Request.PhysicalApplicationPath+("/Bin/WebSet.xml");

其中System.Web.HttpContext.Current.Request.PhysicalApplicationPath表示的是项目的根目录。 

 

////////------>

ds.ReadXml(HttpContext.Current.Server.MapPath("/Citys.xml"));

如果问题出来了:

未能映射路径“/Citys.xml”。

说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

异常详细信息: System.InvalidOperationException: 未能映射路径“/Contacter.xml”。把代码改成:

ds.ReadXml(HttpContext.Current.Server.MapPath("~/Citys.xml"));

///////

        if (!IsPostBack)

        { 

           string myStr = ConfigurationManager.ConnectionStrings["MapGuidingBusinessConnectionString"].ConnectionString.ToString(); 

           SqlConnection myConn = new SqlConnection(myStr); 

           SqlDataAdapter adapter = new SqlDataAdapter("select * from OY_Location", myConn);

            DataSet ds = new DataSet("markers");

            adapter.Fill(ds, "marker"); 

           string sXml = ds.GetXml(); 

           string sFileName = Server.MapPath("Location.xml"); //假设你保存成xmlFile目录下b.xml 

           // Server.MapPath(@".\xmlFile\a.xml") 

           StreamWriter sr = File.CreateText(sFileName);  

          sr.WriteLine(sXml); 

           sr.Close();

        } 

其他回答

关于"未能映射路径"问题 - 露水丛生 - 博客园https://www.cnblogs./lushuicongsheng/archive/2010/12/14/1905813.html

以上问题属网友观点,不代表本站立场,仅供参考!