首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >App_Data目录在ASP.NET5 MVC6中

App_Data目录在ASP.NET5 MVC6中
EN

Stack Overflow用户
提问于 2015-07-23 05:57:09
回答 2查看 16.7K关注 0票数 26

我一直在尝试ASP.NET5 MVC6应用程序。在上一个版本中,有一个目录App_Data。我使用这个文件夹来存储错误日志。但在最新版本中没有发现。有什么帮助吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-01-20 14:21:36

这适用于带有Core2的ASP.NET MVC

代码语言:javascript
复制
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文件夹的位置。

代码语言:javascript
复制
string dataDir = AppDomain.CurrentDomain.GetData("DataDirectory").ToString();
票数 27
EN

Stack Overflow用户

发布于 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

票数 16
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31579229

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档