【问题标题】:Configure ASP.NET Core App to set new default files配置 ASP.NET Core App 以设置新的默认文件
【发布时间】:2016-06-15 01:54:07
【问题描述】:

我浏览了为Use Static Files 为 ASP.NET 核心应用程序提供的文档。从Serving a default documentUsing the UseFileServer method部分阅读信息后,我的脑海中分别打开了以下两个问题:

  1. 如果新的默认文件在 wwwroot 之外,我该如何添加它

  2. 如何使用 UseFileServer 扩展方法添加甚至位于 www 下的新默认文件

【问题讨论】:

    标签: asp.net-core .net-core


    【解决方案1】:

    在您的 Startup.Configure 方法中,您可以配置默认文件:

    DefaultFilesOptions options = new DefaultFilesOptions();
    options.DefaultFileNames.Clear();
    options.DefaultFileNames.Add("myDefault.html"); // this had no influence :-(
    app.UseDefaultFiles(options);
    

    如果我定义以下选项,我可以通过/StaticFiles 加载默认的index.html,但不能加载我自定义的myDefault.html,这可能是你想要的。

    app.UseFileServer(new FileServerOptions()
    {
        FileProvider = new PhysicalFileProvider(@"C:\temp\"),
        RequestPath = new PathString("/StaticFiles"),
        EnableDefaultFiles = true,
        EnableDirectoryBrowsing = false
    });
    

    UseDefaultFiles 似乎没有任何影响。但是,如果您在 Web 服务器中配置默认​​文件,它仍然可以工作。 FileServerOptions 有一个属性DefaultFiles,但它是只读的。

    【讨论】:

    • 其实我的问题比你提到的要多一点。我不想更改根位置,但是 1 我想从 wwwroot 之外添加更多默认文件。因此,我希望将 wwwroot 下默认存在的任何一个与局外人结合起来。 2,使用app.UseFileServer扩展方法实现从wwwroot添加新的默认文件。
    • 我是这么认为的。我尝试了同样的方法,但无法让它工作,除了在 IIS (index.html) 中配置的默认页面。 UseDefaultFiles 是否使用新的默认文件名可能取决于 Web 服务器。
    猜你喜欢
    • 2021-02-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-20
    • 2019-09-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-14
    相关资源
    最近更新 更多