为什么需要在ASP.NET Core MVC中设置"UseContentRoot(AppContext.BaseDirectory)"? [英] Why need to set up "UseContentRoot(AppContext.BaseDirectory) in ASP.NET Core MVC"?

查看:131
本文介绍了为什么需要在ASP.NET Core MVC中设置"UseContentRoot(AppContext.BaseDirectory)"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么需要在ASP.NET Core MVC中设置 UseContentRoot(AppContext.BaseDirectory)?

Why need to set up UseContentRoot(AppContext.BaseDirectory) in ASP.NET Core MVC?

推荐答案

来自

From the docs (which in this case I wrote):

将Directory.GetCurrentDirectory指定为内容根目录时,从该文件夹中启动应用程序时(例如,从Web项目文件夹中调用dotnet运行),它将使用Web项目的根目录文件夹作为应用程序的内容根目录.这是Visual Studio和dotnet新模板中使用的默认设置.

Specifying Directory.GetCurrentDirectory as the content root will use the web project's root folder as the app's content root when the app is started from this folder (for example, calling dotnet run from the web project folder). This is the default used in Visual Studio and dotnet new templates.

如果不添加此目录,则内容根目录将默认为应用程序根目录,该目录是程序运行所在的位置(可能在/bin文件夹中的某个位置).如果要从源/项目根目录启动Web应用程序,通常这不是您想要的.

If you don't add this, the content root will default to the application root, which is wherever the program is running from (probably somewhere in a /bin folder). This usually isn't what you want if you're launching the web app from its source/project root.

这篇关于为什么需要在ASP.NET Core MVC中设置"UseContentRoot(AppContext.BaseDirectory)"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆