Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4c53a86

Browse filesBrowse files
Add option to configure the status code when a version is unsupported
1 parent 0a99931 commit 4c53a86
Copy full SHA for 4c53a86

File tree

Expand file treeCollapse file tree

1 file changed

+34
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+34
-0
lines changed

‎src/Common/src/Common/ApiVersioningOptions.cs

Copy file name to clipboardExpand all lines: src/Common/src/Common/ApiVersioningOptions.cs
+34Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
namespace Asp.Versioning;
44

55
using Asp.Versioning.Routing;
6+
#if NETFRAMEWORK
7+
using System.Net;
8+
#endif
69
using static Asp.Versioning.ApiVersionReader;
710

811
/// <summary>
@@ -100,4 +103,35 @@ public IApiVersioningPolicyBuilder Policies
100103
get => apiVersioningPolicyBuilder ??= new ApiVersioningPolicyBuilder();
101104
set => apiVersioningPolicyBuilder = value;
102105
}
106+
107+
/// <summary>
108+
/// Gets or sets the HTTP status code used for unsupported versions of an API.
109+
/// </summary>
110+
/// <value>The HTTP status code. The default value is 400 (Bad Request).</value>
111+
/// <remarks>
112+
/// <para>While any HTTP status code can be provided, the following are the most sensible:</para>
113+
/// <list type="table">
114+
/// <listheader>
115+
/// <term>Status</term>
116+
/// <description>Description</description>
117+
/// </listheader>
118+
/// <item>
119+
/// <term>400 (Bad Request)</term>
120+
/// <description>The API doesn't support this version</description>
121+
/// </item>
122+
/// <item>
123+
/// <term>404 (Not Found)</term>
124+
/// <description>The API doesn't exist</description>
125+
/// </item>
126+
/// <item>
127+
/// <term>501 (Not Implemented)</term>
128+
/// <description>The API isn't implemented</description>
129+
/// </item>
130+
/// </list>
131+
/// </remarks>
132+
#if NETFRAMEWORK
133+
public HttpStatusCode UnsupportedApiVersionStatusCode { get; set; } = HttpStatusCode.BadRequest;
134+
#else
135+
public int UnsupportedApiVersionStatusCode { get; set; } = 400;
136+
#endif
103137
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.