问题
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