我一直在尝试ASP.NET5 MVC6应用程序。在上一个版本中,有一个目录App_Data。我使用这个文件夹来存储错误日志。但在最新版本中没有发现。有什么帮助吗?
发布于 2018-01-20 14:21:36
这适用于带有Core2的ASP.NET MVC
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
// Use this code if you want the App_Data folder to be in wwwroot
//string baseDir = env.WebRootPath;
// Use this if you want App_Data off your project root folder
string baseDir = env.ContentRootPath;
AppDomain.CurrentDomain.SetData("DataDirectory", System.IO.Path.Combine(baseDir, "App_Data"));
}现在,您可以将这段代码放在需要它以获取App_Data文件夹的位置。
string dataDir = AppDomain.CurrentDomain.GetData("DataDirectory").ToString();发布于 2015-07-23 15:41:48
我认为把App_Data放在wwwroot下是个坏主意。使用asp.net 5,当我们发布/部署时,我们会得到两个文件夹,接近和www.root。任何不能由http请求提供服务的文件都不应该存在于www.root下。如果以前在App_Data文件夹下的东西能住在某个被批准的地方会更好。这个related question of how to access files from approot should be of help
https://stackoverflow.com/questions/31579229
复制相似问题