OWIN发送多个路由静态文件 [英] OWIN send static file for multiple routes

查看:704
本文介绍了OWIN发送多个路由静态文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在做这坐落在ASP.Net的WebAPI顶部的SPA。我等着使用HTML5的历史,而不是#/ 对历史路由但这带来了一个问题的深层链接,我需要确保 / /富/条都返回相同的HTML文件(和我的JS将使得SPA的右侧部分)。



我如何得到OWIN /武士刀返回相同的HTML文件的多个不同的网址吗?


解决方案

为了让事情变得简单,同时仍保持全部缓存善良等。从StaticFiles中间件,我会使用内联刚中间件改写请求路径,像这样



<预类=郎-CS prettyprint-覆盖> 公共类启动
{
公共无效配置(IAppBuilder应用程序)
{
app.Map( /应用程序,温泉= GT;
{
spa.Use((背景下,下一个)=>
{
context.Request.Path =新PathString(/指数的.html);

返回下一个();
});

spa.UseStaticFiles();
});

app.UseWelcomePage();
}
}

这将成为任何东西的欢迎页面,但 /应用/ * ,这将永远服务的index.html来代替。


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 linking, I need to make sure / and /foo/bar all return the same HTML file (and my JS will render the right part of the SPA).

How do I get OWIN/Katana to return the same HTML file for multiple different urls?

解决方案

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.

这篇关于OWIN发送多个路由静态文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆