我有一个非常简单的角度应用程序项目,只需要提供来自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.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。