“找不到路径的一部分” C# IIS 在生产环境中的部署
我正在从我的应用程序加载一个 xml 文件:
XDocument.Load(HttpContext.Current.Server.MapPath("/") + "XMLMetadata\\Actions.1.xml");
在开发环境中它工作正常。
但是我部署应用程序后,系统找不到它。
这是错误:异常详细信息:System.IO.DirectoryNotFoundException:找不到路径“C:\inetpub\wwwroot\XMLMetadata\Actions.1.xml”的一部分。
该文件已部署到C:\inetpub\wwwroot\MyApp\XMLMetadata\Actions.1.xml
而不是:C:\inetpub\wwwroot\XMLMetadata\Actions.1.xml
ASP .NET 4 MVC 应用程序 我缺少什么?
I am loading an xml file from my applicatin:
XDocument.Load(HttpContext.Current.Server.MapPath("/") + "XMLMetadata\\Actions.1.xml");
In the dev environment it is working fine.
But After I deploy the application, the system cannot find it.
this is the error:Exception Details: System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\inetpub\wwwroot\XMLMetadata\Actions.1.xml'.
the file was deployed toC:\inetpub\wwwroot\MyApp\XMLMetadata\Actions.1.xml
and not to:C:\inetpub\wwwroot\XMLMetadata\Actions.1.xml
ASP .NET 4 MVC APPLICATION
What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
嗯 - 您的意思是问为什么它部署到
C:\inetpub\wwwroot\MyApp\XMLMetadata\
而不是C:\inetpub\wwwroot\XMLMetadata\
?事实上,您已经回答了出现错误的原因。
正是出于这个原因,您尝试使用引用 URL,即
~\XMLMetadata\
而不是硬编码位置。还要确保您在本地使用 IIS 在开发系统上进行测试。
Hmm - do you mean to ask why it has deployed to
C:\inetpub\wwwroot\MyApp\XMLMetadata\
rather thanC:\inetpub\wwwroot\XMLMetadata\
?As it is you've answered the reason why you get an error.
It is for this reason that you try and use referential URLs i.e.
~\XMLMetadata\
rather than a hard coded location.Also ensure that you test on the development system using IIS locally.
我很确定您希望在这种情况下使用“~”。与 Server.MapPath 一起使用的“~”将为您提供应用程序根目录的物理路径。其中“/”将为您提供域名根的物理路径。这些路径可能会有所不同,具体取决于您的 IIS 设置方式。
I'm pretty sure you are looking to use the "~" in this case. The "~" used with Server.MapPath will give you the physical path to the root of the application. Where as "/" will give you the physical path to the root of the domain name. These paths can be different based on how you have IIS setup.
很难说你在这里使用的具体框架和基类是什么,但我猜是 ASP.NET。如果是这样,您可能需要查看
Control.ResolveUrl()
。然后,您应该得到如下所示的内容,而不是
Load()
调用。It's difficult to say what exact framework and base class you are working here, but I'm guessing ASP.NET. If so, you may want to have a look at
Control.ResolveUrl()
.Then, you should get something like the following instead of your
Load()
call.我过去使用过类似的东西:
I've used something like this in the past:
这是因为您的 Web 应用程序位于虚拟目录中,因此您需要解析到该级别:
来自 MSDN 的应用程序路径:
This is because your web application is sat in a virtual directory, so you will need to resolve to that level:
Remarks on ApplicationPath from MSDN: