owin地图扩展名返回404 [英] owin map extension return 404

查看:115
本文介绍了owin地图扩展名返回404的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图仅为Web API操作实现中间件,所以我发现MapIAppBuilder接口的扩展方法.我检查了katana源代码[ 1 ],此方法返回与Use方法相同的IAppBuilder.

I tried to implement a middleware just for my web API actions, so i found Map that is a extension method of IAppBuilder inerface. i checked katana source code [1], this method return an IAppBuilder same as Use method.

但是在owin/WebAPI中,我不知道为什么控制器在映射后不解决?

but in owin/WebAPI i don't know why controllers dose not resolve after mapping?

在调用下一个中间件后很清楚,owin应该运行下一个中间件,但是映射后似乎没有下一个中间件,我的错误在哪里?

its clear after invoking next middleware, owin should run next middleware, but after mapping it seems there is no next middleware, where is my mistake?

启动:

        public void Configuration(IAppBuilder app)
        {
            ConfigureOAuth(app);
            app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);


            app = app.Map("/api", application => {
                ConfigurationAPI(application);
            });


            app.Use<ExceptionMiddleware>();
            //app.UseWebApi(config);
        }


        public void ConfigurationAPI(IAppBuilder app)
        {
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            FilterConfig.RegisterHttpFilters(GlobalConfiguration.Configuration.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);

            HttpConfiguration config = new HttpConfiguration();
            WebApiConfig.Register(config);

            SimpleInjectorBootstrapper.Initialize();
            DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(SharedLayer.Core.CoreObject.container));
            config.DependencyResolver = new SimpleInjectorWebApiDependencyResolver(SharedLayer.Core.CoreObject.container);

            app = app.Use<ExceptionMiddleware>();
            app = app.Use<AuthenticateMiddleware>();
            app.UseWebApi(config);

        }

但是当我添加以下运行块时,所有请求都返回"test"!

but when I add following run block, all requests return "test"!!

        app.Run(async context =>
        {
            await context.Response.WriteAsync("test");
        });
        app.UseWebApi(config);

推荐答案

您的路线定义是否包含/api段? Map会将其从管道的分支(ConfigurationAPI)的路径中删除.

Do your route definitions include the /api segment? Map removes that from the path for it's branch of the pipeline (ConfigurationAPI).

这篇关于owin地图扩展名返回404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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