一般加载xml路径,我们都会用
string Path =System.Web.HttpContext.Current.Server.MapPath("~/App_Data/Config.xml")
XmlDocument xd = new XmlDocument();
xd.Load(Path);
以上代码可以正常执行.
但在Application_Start,用到Current对象时(如Response,Server),会报未将对象引用设置到对象的实例。
现在只能退一步不用Current.
遇到问题是取加载路径,
用System.Web.HttpRuntime.AppDomainAppVirtualPath + "/App_Data/Config.xml"去替换,执行时间报错找不到文件。
如何解决,难道不用Server.MapPath,就读不到web项目文件?求解。。
另外若能处理Application_Start中 HttpContext.Current对象不能为空方法也行。
string Path =System.Web.HttpContext.Current.Server.MapPath("~/App_Data/Config.xml")
XmlDocument xd = new XmlDocument();
xd.Load(Path);
以上代码可以正常执行.
但在Application_Start,用到Current对象时(如Response,Server),会报未将对象引用设置到对象的实例。
现在只能退一步不用Current.
遇到问题是取加载路径,
用System.Web.HttpRuntime.AppDomainAppVirtualPath + "/App_Data/Config.xml"去替换,执行时间报错找不到文件。
如何解决,难道不用Server.MapPath,就读不到web项目文件?求解。。
另外若能处理Application_Start中 HttpContext.Current对象不能为空方法也行。
解决方案 »
- 求大虾啊!!!
- webqq
- petshop4.0注册问题
- 关于asp.net 2.0中的 日历控件问题
- showModalDialog与父窗口中gridview刷新的问题
- 路径问题请教!!!Could not find a part of the path
- 请问这样的储存过程怎么写??
- 帮我看一下,怎么样才能保持连接
- 为什么在我的global.asmx文件中不能用<script language="vb" runat="server">
- 在datagrid中,怎么控制从数据库里调出内容的多少。
- 急求...在ashx.cs文件中,可以同时传一个List跟一个数组到页面吗
- ASP.NET网站后期问题!!
用这个 HttpRuntime.AppDomainAppPath
Response.Write(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "App_Data\\Config.xml")+"<br/>");
Response.Write(System.Web.HttpRuntime.AppDomainAppPath + "App_Data\\Config.xml" + "<br/>");