C# HttpContext.Current.Server.MapPath()出错
我将此代码用作类的一部分,该类应连接到Access数据库:C# HttpContext.Current.Server.MapPath()出错,c#,server.mappath,C#,Server.mappath,我将此代码用作类的一部分,该类应连接到Access数据库: string path = HttpContext.Current.Server.MapPath("App_Data"); App_数据文件夹位于项目中,包含数据库,但MapPath()以某种方式返回null 如何解决此问题?尝试使用: string folder = System.Web.HttpContext.Current != null ? System.IO.Path.Combine(AppDomai
string path = HttpContext.Current.Server.MapPath("App_Data");
App_数据文件夹位于项目中,包含数据库,但MapPath()
以某种方式返回null
如何解决此问题?尝试使用:
string folder = System.Web.HttpContext.Current != null ?
System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "App_data") :
System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
看一看如何尝试传递相对名称“/App\u Data”或“~/App\u Data”。