asp.net-core - 如何在 ASP.NET Core 中为 wwwroot 配置替代文件夹?

标签 asp.net-core

是否可以配置不同的文件夹来替换 ASP.NET Core 中的 wwwroot?如果是,这种变化如何以及是否有任何副作用?

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

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

最佳答案

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



是的。添加 UseWebRoot调用您的 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?



以下是我能想到的三个:
  • Bower 包管理器将无法正常工作,因为它会查找 lib文件夹在 wwwroot .我不确定这是否可以配置。
  • 您需要修复 bundleconfig.json查看新目录。
  • 您将需要更新 include project.json 中的部分将您的新目录包含在发布输出中。
  • 关于asp.net-core - 如何在 ASP.NET Core 中为 wwwroot 配置替代文件夹?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40535388/

    相关文章:

    c# - Postman 为简单的 ASP.NET Core Web API 获取 404 错误

    asp.net-core - Entity Framework Core 始终返回外部行的空列表

    c# - Automapper Custom Map 使用 "Include"来获取 child 数

    c# - Automapper 在 Profile 类中注入(inject) DbContext

    c# - ASP.Net 核心 2 : Default Authentication Scheme ignored

    asp.net-core - 如何在环境已知之前加载 appSettings.{environment}.json ? (ASPNetCore)

    c# - ASP.NET Core 作为 Windows 服务 wwwroot 位置

    c# - 如何在 F# Giraffe Web API 中检索 url 编码形式?

    visual-studio-2015 - VS 2015 中的 ASP.NET MVC6 引用

    asp.net-core - 将策略应用于 ASP.NET Core 应用程序中的路径