【发布时间】:2014-08-04 07:30:13
【问题描述】:
我已经尝试了这些选项:
var resourcePath = "data.xml";
Application files are located in: c:/MyApp/bin/Release.
AppDomain.CurrentDomain.BaseDirectory refers to "c:/MyApp" folder.
AppDomain.CurrentDomain.SetupInformation.PrivateBinPath refers to "c:/MyApp/bin/Release" folder.
HttpContext.Current.Server.MapPath(resourcePath) refers to http://www.domain.com/MyApp/data.xml
只有 PrivateBinPath 有效,但根据定义,它可以包含多个 bin 目录,所以也许我不应该使用它。
Web API 应用程序访问 Bin 文件夹中文件的标准方法是什么?
【问题讨论】:
-
标准规定数据文件在 APP_DATA 文件夹中,而不是在 BIN 文件夹中。你能解释一下为什么在那个文件夹中需要这个文件吗?
-
是的,我同意,但这是一个带有 asp.net 3.5 的旧版应用程序。无论如何,您在 bin 文件夹中复制后如何访问该文件?
-
你试过
HttpContext.Current.Server.MapPath("~/bin", "data.xml")吗? -
非常感谢,是的工作:)
标签: c# asp.net asp.net-web-api appdomain httpcontext