加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – 默认情况下提供静态文件index.html

发布时间:2020-12-15 19:27:39 所属栏目:asp.Net 来源:网络整理
导读:我有一个非常简单的角度应用程序项目,只需要提供来自wwwroot的静态文件.这是我的Startup.cs: public class Startup{ public void ConfigureServices(IServiceCollection services) { } public void Configure(IApplicationBuilder app) { app.UseIISPlatfor
我有一个非常简单的角度应用程序项目,只需要提供来自wwwroot的静态文件.这是我的Startup.cs:
public class Startup
{
    public void ConfigureServices(IServiceCollection services) { }

    public void Configure(IApplicationBuilder app)
    {
        app.UseIISPlatformHandler();
        app.UseStaticFiles();
    }

    // Entry point for the application.
    public static void Main(string[] args) => WebApplication.Run<Startup>(args);
}

每当我使用IIS Express或web启动项目时,我总是必须导航到/index.html.我该如何制作它以便我可以访问根(/)并仍然获得index.html?

解决方法

您想要服务器默认文件和静态文件:
public void Configure(IApplicationBuilder application)
{
    ...
    // Enable serving of static files from the wwwroot folder.
    application.UseStaticFiles();
    // Serve the default file,if present.
    application.UseDefaultFiles();
    ...
}

或者,您可以使用UseFileServer方法,该方法使用单行而不是两行来执行相同的操作.

public void Configure(IApplicationBuilder application)
{
    ...
    application.UseFileServer();
    ...
}

有关更多信息,请参见documentation.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读