Skip to content

Commit 75305e8

Browse files
Chris Martinezcommonsensesoftware
authored andcommitted
Fix API version route constraint
1 parent 106507d commit 75305e8

File tree

3 files changed

+11
-15
lines changed

3 files changed

+11
-15
lines changed

src/Microsoft.AspNet.WebApi.Versioning/Dispatcher/HttpResponseExceptionFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace Microsoft.Web.Http.Dispatcher
22
{
3+
using Microsoft.Web.Http.Versioning;
34
using System;
45
using System.Collections.Generic;
56
using System.Diagnostics.CodeAnalysis;
@@ -9,7 +10,6 @@
910
using System.Web.Http;
1011
using System.Web.Http.Dispatcher;
1112
using System.Web.Http.Tracing;
12-
using Microsoft.Web.Http.Versioning;
1313
using static ApiVersion;
1414
using static System.Net.HttpStatusCode;
1515
using static System.String;

src/Microsoft.AspNet.WebApi.Versioning/Routing/ApiVersionRouteConstraint.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,7 @@ public bool Match( HttpRequestMessage request, IHttpRoute route, string paramete
2929
return false;
3030
}
3131

32-
var properties = request.ApiVersionProperties();
33-
34-
if ( values.TryGetValue( parameterName, out string value ) )
35-
{
36-
properties.RawRequestedApiVersion = value;
37-
}
38-
else
32+
if ( !values.TryGetValue( parameterName, out string value ) )
3933
{
4034
return false;
4135
}
@@ -45,6 +39,10 @@ public bool Match( HttpRequestMessage request, IHttpRoute route, string paramete
4539
return !IsNullOrEmpty( value );
4640
}
4741

42+
var properties = request.ApiVersionProperties();
43+
44+
properties.RawRequestedApiVersion = value;
45+
4846
if ( TryParse( value, out var requestedVersion ) )
4947
{
5048
properties.RequestedApiVersion = requestedVersion;

src/Microsoft.AspNetCore.Mvc.Versioning/Routing/ApiVersionRouteConstraint.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,7 @@ public bool Match( HttpContext httpContext, IRouter route, string routeKey, Rout
3030
return false;
3131
}
3232

33-
var feature = httpContext.Features.Get<IApiVersioningFeature>();
34-
35-
if ( values.TryGetValue( routeKey, out string value ) )
36-
{
37-
feature.RawRequestedApiVersion = value;
38-
}
39-
else
33+
if ( !values.TryGetValue( routeKey, out string value ) )
4034
{
4135
return false;
4236
}
@@ -46,6 +40,10 @@ public bool Match( HttpContext httpContext, IRouter route, string routeKey, Rout
4640
return !IsNullOrEmpty( value );
4741
}
4842

43+
var feature = httpContext.Features.Get<IApiVersioningFeature>();
44+
45+
feature.RawRequestedApiVersion = value;
46+
4947
if ( TryParse( value, out var requestedVersion ) )
5048
{
5149
feature.RequestedApiVersion = requestedVersion;

0 commit comments

Comments
 (0)