相关疑难解决方法(0)

包装StaticFileMiddleware以重定向404错误

我正在尝试将自定义中间件注入到我的OWIN管道中,该管道包装StaticFileMiddleware来自MS 的可用,以支持AngularJS中的HTML 5模式.我一直在关注这个指南:http://geekswithblogs.net/shaunxu/archive/2014/06/10/host-angularjs-html5mode-in-asp.net-vnext.aspx

从我可以收集到的如何工作,我的中间件将请求传递给静态文件中间件,然后如果它无法解决这些请求(即,请求HTML 5角度路径,"/无论如何"),它返回基本角度页面,以便对HTML 5路径的硬请求将起作用.

我的问题是调用内部中间件的结果似乎总是200状态代码,即使在我的浏览器中我得到404,这让我挠头.这是我的代码供参考:

public static class AngularServerExtension
{
    public static IAppBuilder UseAngularServer(this IAppBuilder builder, string rootPath, string entryPath)
    {
        var options = new AngularServerOptions()
        {
            FileServerOptions = new FileServerOptions()
            {
                EnableDirectoryBrowsing = false,
                FileSystem = new PhysicalFileSystem(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, rootPath))
            },
            EntryPath = new PathString(entryPath)
        };

        builder.UseDefaultFiles(options.FileServerOptions.DefaultFilesOptions);
        return builder.Use(new Func<AppFunc, AppFunc>(next => new AngularServerMiddleware(next, options).Invoke));           
    }
}

public class AngularServerMiddleware
{
    private readonly AngularServerOptions _options;
    private readonly AppFunc _next;
    private readonly StaticFileMiddleware _innerMiddleware; …
Run Code Online (Sandbox Code Playgroud)

asp.net angularjs owin

8
推荐指数
1
解决办法
3627
查看次数

标签 统计

angularjs ×1

asp.net ×1

owin ×1