I have implemented Web API Controller with PUT method (I marked method with HttpPut attribute from System.Web.Http).
And when I try to make put request, i have message
The requested resource does not support http method 'PUT'.
I remove webdav in Web.Config, added put etc.
But it is still not work.
How I can resolve this problem?
Make sure that the param names on your URL match with some param names in your controller method declaration. This simple mistake can cause 405.
Related
A thirdparty is calling the following URI but I'm unable to retreive the parameters :
http://host:port/#property1=abc&property2=123
I created an AspNetCore WebApi controller with an empty controller name and an empty route name.
So far, I can receive the call but I'm unable to read the property1 and property2.
Those are not parameters from body, nor from Route/Query.
Last resort would be to retreive the full received URI and parse it with a regex but I'm also not able to (I tried to setup an ActionFilterAttribute but I'm stuck getting the called URI).
So far this is exceeding my webapi knowledge.
Thank you
No... hash parameters are not sent so server and is only used by the browser.
You can use ? Instead of # to get it on the server.
What alternative do I have to avoid 405 Method Not Allowed error when using Put or Delete method in Web API?
I know there are a lot of solutions that specifically mention removing WebDAV from IIS, or disabling it from the Web.config, or other similar options
For Example:
"405 method not allowed" in IIS7.5 for "PUT" method and
ASP.NET Web API - PUT & DELETE Verbs Not Allowed - IIS 8
But I have had multiple situations where these were either not viable solutions or they simply didn't work.
One alternative is to use Post instead of the Put or Delete method, you can do this by adding some decorators to the functions:
For Example:
[HttpPost]
[Route("api/Users/Update")]
[ResponseType(typeof(void))]
public IHttpActionResult PutUser(User user)
{...
The [HttpPost] decorator just indicates that the function is a Post.
And the Route is going to override the default routing in your WebApiConfig.cs.
I hope this makes it easier for someone in the future.
I had followed the tutorial about, how to create OData endpoint on the page http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api/odata-v4/create-an-odata-v4-endpoint.
It works as expected
The request about metadata, it works as expected to:
When I make a request to url http://localhost:21937/Products, then I've got all entries from products
My questions are:
What is the rootservice of this?
How can I query the ressource types like
ResourceTypes('Namespace.Product')
Not sure what you mean root service, but if you mean how to route a call to an action of controller, in this sample, OData Web API routing conversion is been used, and more detail can refer to http://odata.github.io/WebApi/#03-02-built-in-routing-conventions
If you mean the type information, the you can query http://localhost:21937/$metadata
I have a few controllers and a few methods decorated with a [Route] attribute.
Now the thing is, i want to add a global message handler excluding one single controller.
here is a snapshot from the http configuration code:+
The problem is, my Free controller (defined in the FreeApi route) is still getting the Custom message handler somehow in the pipeline.
How can i achieve this kind of behavior?
Thanks!
I need to create ASP.NET WebApi with couple operation, for example RegisterAppStart, RegisterStep and RegisterAppEnd. And I want to place all this actions in one controller. As I read, usually in WebApi action name is not using.
And my question - is this a bad idea to rewrite default route config with actions using?
ps. sorry for my English
You can give actions arbitrary names using the [Route("/api/FooController/BarMethod"] attribute routing.
This usually overrides the "REST"yness of your service (where the request method indicates which method should be called), but as you aren't really building a REST service, you shouldn't care.