We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
https://www.hanselman.com/blog/HTTPPUTOrDELETENotAllowedUseXHTTPMethodOverrideForYourRESTServiceWithASPNETWebAPI.aspx
The text was updated successfully, but these errors were encountered:
For POST instead of PATCH use HttpMethodOverrideMiddleware
POST
PATCH
HttpMethodOverrideMiddleware
public void Configure(IApplicationBuilder app) { app.UseHttpMethodOverride(); app.UseMvc(); }
For PUT instead of PATCH create custom middleware
PUT
public class MethodOverrideMiddleware { private readonly RequestDelegate _next; readonly string[] _methods = { "DELETE", "PATCH", "PUT" }; const string _header = "X-Http-Method-Override"; public MethodOverrideMiddleware(RequestDelegate next) { _next = next; } public Task Invoke(HttpContext context) { if (HttpMethods.IsPut(context.Request.Method) && context.Request.Headers.ContainsKey(_header)) { var method = context.Request.Headers[_header].ToString(); if (_methods.Contains(method)) { context.Request.Method = method; } } return _next.Invoke(context); } }
and use it in Startup.cs
app.UseMiddleware<CustomMethodOverrideMiddleware>();
Sorry, something went wrong.
Marusyk
No branches or pull requests
https://www.hanselman.com/blog/HTTPPUTOrDELETENotAllowedUseXHTTPMethodOverrideForYourRESTServiceWithASPNETWebAPI.aspx
The text was updated successfully, but these errors were encountered: