asp.Net   发布时间:2022-04-07  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了asp.net – 默认情况下提供静态文件index.html大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个非常简单的角度应用程序项目,只需要提供来自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.

大佬总结

以上是大佬教程为你收集整理的asp.net – 默认情况下提供静态文件index.html全部内容,希望文章能够帮你解决asp.net – 默认情况下提供静态文件index.html所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。