OWIN send static file for multiple routes

后端 未结 2 1121
北海茫月
北海茫月 2021-02-02 17:59

I\'m making a SPA which sits on top of ASP.Net WebAPI. I\'m waiting to use HTML5 history rather than #/ for history routing but that poses a problem for deep linkin

2条回答
  •  终归单人心
    2021-02-02 19:00

    To make things simple, while still keeping all the caching goodness etc. from the StaticFiles middleware, I'd just rewrite the request path using an inline middleware, like this

    public class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            app.Map("/app", spa =>
            {
                spa.Use((context, next) =>
                {
                    context.Request.Path = new PathString("/index.html");
    
                    return next();
                });
    
                spa.UseStaticFiles();
            });
    
            app.UseWelcomePage();
        }
    }
    

    This will serve the welcome page on anything but /app/*, which will always serve index.html instead.

提交回复
热议问题