owin map extension return 404

白昼怎懂夜的黑 提交于 2019-12-11 06:25:07

问题


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.

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

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?

StartUp:

        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);

        }

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

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

回答1:


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



来源:https://stackoverflow.com/questions/45188385/owin-map-extension-return-404

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!