I was able to get the standard GET, POST, PUT, and DELETE verbs working ok. Some of our clients will need the HEAD verb to work as well.
Essentially, HEAD is just a GET but only the headers are returned. It's generally used to determine the size of the content that could be requested by the corresponding GET, and then providing a download progress bar. It's also good for debugging.
I tried adding a "Head" method to the ApiController subclass, and it compiles, but doesn't return the correct response. I'm getting:
HTTP/1.1 405 Method Not Allowed
Is this supported in this version? Or, are there any plans to support it moving forward? Or, any workarounds?
Currently only GET, PUT, POST, DELETE can be implied from the action name. However, you should be able to attribute the action with AcceptVerbs("HEAD") to be able to allow HEAD requests.
Any idea why System.Web.Http.Routing.HttpMethodConstraint doesn't work in the MVC hosted app?
I think you have to use System.Web.Routing.HttpMethodConstraint for MVC. Yes there are two objects with the same name under two different (and similar) namespaces.. :) I really hope they'll combine those at some
point.
Thanks! I subsequently tried using both versions of the constraint with the contact manager sample, and it actually worked for me. Sadly, haven't been able to figure out/ haven't had the time to check why it doesn't work with my specific code :(
Please "Mark as Answer" if this resolves your query. Thanks!
Lavamantis
0 Points
1 Post
WebAPI support HEAD verb?
Feb 21, 2012 10:53 PM|LINK
I was able to get the standard GET, POST, PUT, and DELETE verbs working ok. Some of our clients will need the HEAD verb to work as well.
Essentially, HEAD is just a GET but only the headers are returned. It's generally used to determine the size of the content that could be requested by the corresponding GET, and then providing a download progress bar. It's also good for debugging.
I tried adding a "Head" method to the ApiController subclass, and it compiles, but doesn't return the correct response. I'm getting:
HTTP/1.1 405 Method Not Allowed
Is this supported in this version? Or, are there any plans to support it moving forward? Or, any workarounds?
head 405
vinelap
Member
28 Points
9 Posts
Microsoft
Re: WebAPI support HEAD verb?
Feb 22, 2012 12:19 AM|LINK
Currently only GET, PUT, POST, DELETE can be implied from the action name. However, you should be able to attribute the action with AcceptVerbs("HEAD") to be able to allow HEAD requests.
[AcceptVerbs("HEAD")] public void Test(){}SiggiGG
Member
265 Points
105 Posts
Re: WebAPI support HEAD verb?
Feb 22, 2012 08:12 AM|LINK
And if you want to run a certain action/method for the HEAD requests, you can use a route constraint.
For example:
routes.MapHttpRoute( name: "BookHead", routeTemplate: "api/books/{productNumber}", defaults: new { controller = "Books", action = "Header" }, constraints: new { productnumber = @"\d+", httpMethod = new HttpMethodConstraint("HEAD") } );priya_marwah...
Member
81 Points
52 Posts
Re: WebAPI support HEAD verb?
Mar 26, 2012 05:10 PM|LINK
Any idea why System.Web.Http.Routing.HttpMethodConstraint doesn't work in the MVC hosted app?
SiggiGG
Member
265 Points
105 Posts
Re: WebAPI support HEAD verb?
Mar 26, 2012 05:12 PM|LINK
I think you have to use System.Web.Routing.HttpMethodConstraint for MVC. Yes there are two objects with the same name under two different (and similar) namespaces.. :) I really hope they'll combine those at some point.
priya_marwah...
Member
81 Points
52 Posts
Re: WebAPI support HEAD verb?
Mar 28, 2012 06:54 AM|LINK
Thanks! I subsequently tried using both versions of the constraint with the contact manager sample, and it actually worked for me. Sadly, haven't been able to figure out/ haven't had the time to check why it doesn't work with my specific code :(
Erik Marcuss...
Member
17 Points
12 Posts
Re: WebAPI support HEAD verb?
Mar 28, 2012 07:33 PM|LINK
Discussed here: http://forums.asp.net/t/1777747.aspx/1?System+Web+Http+Routing+IHttpRouteConstraint+vs+System+Web+Routing+IRouteConstraint