如何在ASP.NET Core中为wwwroot配置替代文件夹? [英] How to Configure an Alternative Folder to wwwroot in ASP.NET Core?

查看:60
本文介绍了如何在ASP.NET Core中为wwwroot配置替代文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在ASP.NET Core中配置其他文件夹来替换wwwroot?如果是的话,此更改如何产生副作用?

Is it possible to configure a different folder to replace wwwroot in ASP.NET Core? And if yes, how and are there any side effects to this change?

在整个项目中当前唯一包含 wwwroot 的配置可以在 project.json 中找到,如以下代码所示;但是用新文件夹的名称替换值不足以读取静态文件(例如: index.html ).

The only config that currently includes wwwroot in the entire project is found in project.json as seen in the code below; but replacing the value with the name of the new folder is not enough for the static file (ex: index.html) to be read.

"publishOptions": {
"include": [
  "wwwroot",
  "web.config"
]
},

推荐答案

是否可以在ASP.NET Core中配置其他文件夹来替换wwwroot?

Is it possible to configure a different folder to replace wwwroot in ASP.NET Core?

是的.在您的 Program 类中添加一个 UseWebRoot 调用:

Yes. Add a UseWebRoot call in your Program class:

public static void Main(string[] args)
{
    var host = new WebHostBuilder()
        .UseKestrel()
        .UseWebRoot("myroot") // name it whatever you want
        .UseContentRoot(Directory.GetCurrentDirectory())
        .UseIISIntegration()
        .UseStartup<Startup>()
        .Build();

    host.Run();
}

此更改有副作用吗?

are there any side effects to this change?

我能想到的有三个:

  1. Bower软件包管理器无法正常运行,因为它会在 wwwroot 中寻找 lib 文件夹.我不确定这是否可以配置.
  2. 您需要修复 bundleconfig.json 才能查看新目录.
  3. 您将需要更新 project.json 中的 include 部分,以将新目录包括在发布输出中.
  1. The Bower package manager will not work properly, as it looks for a lib folder in wwwroot. I'm not certain if this is configurable.
  2. You will need to fix bundleconfig.json to look at the new directory.
  3. You will need to update the include portion in project.json to include your new directory in the publish output.

这篇关于如何在ASP.NET Core中为wwwroot配置替代文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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