Sebazzz / SDammann.WebApi.Versioning

Versioning support for ASP.NET Web Api
Apache License 2.0
173 stars 43 forks source link

Accessing invalid version containing letters throws exception #30

Closed douglaslps closed 10 years ago

douglaslps commented 10 years ago

This is my route configuration:

config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{version}/{controller}/{id}", defaults: new { id = RouteParameter.Optional } );

I don't want to use "api/v1/". I like "api/1/" better. I was testing it and if I try to access "api/x/" an exception is thrown:

An error has occurred.Specified cast is not valid.System.InvalidCastException at SDammann.WebApi.Versioning.VersionedControllerSelector.GetVersionRouteDefaults(HttpRequestMessage request) in z:\Developing\Visual Studio\Projects\SDammann.WebApi.Versioning\src\SDammann.WebApi.Versioning\VersionedControllerSelector.cs:line 155 at SDammann.WebApi.Versioning.VersionedControllerSelector.SelectController(HttpRequestMessage request) in z:\Developing\Visual Studio\Projects\SDammann.WebApi.Versioning\src\SDammann.WebApi.Versioning\VersionedControllerSelector.cs:line 118 at System.Web.Http.Dispatcher.HttpControllerDispatcher.SendAsyncCore(HttpRequestMessage request, CancellationToken cancellationToken) at System.Web.Http.Dispatcher.HttpControllerDispatcher.d__0.MoveNext()

Do you think you can fix it? IMHO returning an error saying the version wasn't find would be better.

Sebazzz commented 10 years ago

As this is a breaking change, I prefer to postpone this for vNext.

Sebazzz commented 10 years ago

Your eror has been fixed in vnext branch. Please check out the changes and see if you're happy with it. I have not yet finalized the documentation nor pushed a prerelease package, but based on this file you should be able to get it working.

You can now choose a prefix for versioning in the URL by specifying in the route configuration. For example: api/v{version}/{controller}.

douglaslps commented 10 years ago

Fantastic! Thanks.

Sebazzz commented 10 years ago

I have updated the README :)

Sebazzz commented 9 years ago

Beta 1 of vNext is available: https://www.nuget.org/packages/SDammann.WebApi.Versioning/3.0.0-beta1