You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
causes RouteData to be removed from HttpContext's IRoutingFeature (taken by HttpContext.GetRouteData())
The RouteData still exists in ControllerContext/ActionContext though.
Reproduction:
publicclassStartup{publicStartup(IHostingEnvironmentenv){varbuilder=newConfigurationBuilder().AddEnvironmentVariables();Configuration=builder.Build();}publicIConfigurationRootConfiguration{get;}publicvoidConfigureServices(IServiceCollectionservices){services.AddMvc();services.AddApiVersioning(o =>{o.AssumeDefaultVersionWhenUnspecified=true;o.DefaultApiVersion=newApiVersion(1,0);});}publicvoidConfigure(IApplicationBuilderapp,IHostingEnvironmentenv,ILoggerFactoryloggerFactory){app.UseMvc();}}publicclassProgram{publicstaticvoidMain(string[]args){BuildWebHost(args).Run();}publicstaticIWebHostBuildWebHost(string[]args)=>WebHost.CreateDefaultBuilder(args).UseStartup<Startup>().Build();}publicclassValuesController:Controller{[HttpGet("/test/{MyValue:int}")]publicstringGet(){// equals to this.HttpContext.Features.Get<IRoutingFeature>().RouteData;varfromHttp=this.HttpContext.GetRouteData();varfromController=this.ControllerContext.RouteData;if(fromHttp.Values.Count!=fromController.Values.Count){thrownewException("Different RouteData values when taken from HttpContext and ActionContext.");}return"VALUE";}}
Web Application: netcoreapp2.0
Microsoft.AspNetCore.Mvc.Versioning: 2.0.0-preview2-final
Microsoft.AspNetCore: 2.0.0
Microsoft.AspNetCore.Mvc: 2.0.0
Operating system: Windows 10 Professional 15063.540
IDE: Visual Studio Professional 2017 15.3.2
The text was updated successfully, but these errors were encountered:
This is an interesting find, but it is a bug. The explanation for why this happens is a bit long, but it occurs during the application of the versioning policy. The original route data is provided to the action context, which eventually makes it's way to the controller context, but the route data is not restored on the route context. The route context provides the route data for the IRoutingFeature. That's why they don't match.
I've located the issue and I should have the fix out soon.
Bug occured after the migration to .NET Core 2.0 / ASP .NET Core 2.0.
Adding ApiVersioning with the method
causes RouteData to be removed from HttpContext's
IRoutingFeature
(taken byHttpContext.GetRouteData()
)The RouteData still exists in
ControllerContext
/ActionContext
though.Reproduction:
Web Application: netcoreapp2.0
Microsoft.AspNetCore.Mvc.Versioning: 2.0.0-preview2-final
Microsoft.AspNetCore: 2.0.0
Microsoft.AspNetCore.Mvc: 2.0.0
Operating system: Windows 10 Professional 15063.540
IDE: Visual Studio Professional 2017 15.3.2
The text was updated successfully, but these errors were encountered: