Tagged Questions
52
votes
4answers
28k views
Multiple HttpPost method in Web API controller
I am starting to use MVC4 Web API project, I have controller with multiple HttpPost methods. The Controller looks like the following:
Controller
public class VTRoutingController : ApiController
{
...
41
votes
8answers
28k views
Post parameter is always null
Since upgrading to RC for WebAPI I'm having some real odd issue when calling POST on my WebAPI.
I've even gone back to the basic version generated on new project. So:
public void Post(string value)
{
...
40
votes
4answers
21k views
Custom method names in ASP.NET Web API
I'm converting from the WCF Web API to the new ASP.NET MVC 4 Web API. I have a UsersController, and I want to have a method named Authenticate. I see examples of how to do GetAll, GetOne, Post, and ...
10
votes
1answer
2k views
composite key resource REST service
I've come across a problem at work where I can't find information on the usual standard or practice for performing CRUD operations in a RESTful web service against a resource whose primary key is a ...
9
votes
1answer
6k views
Enabling CORS with WebAPI PUT / POST requests?
I've tried following this post but I'm still not quite there:
CORS support for PUT and DELETE with ASP.NET Web API
In my web.config I have the following:
<system.webServer>
...
7
votes
3answers
4k views
asp.net webapi 2 attribute routing not working
I have visual studio 2012 installed with mvc4 using .net framework 4.5. Now I want to use webapi2 with attribute writing and i want my hlep page show all the endpoints properly.
In my solution i ...
7
votes
1answer
4k views
How to modify framework's default Web API routes?
It seems there is a built-in default logic for Web API to use the HTTP Verb as the action name if no action was supplied in the URL. For example, I have this route:
...
7
votes
0answers
568 views
Generating version specific help documentation pages for ASP.NET Web API application
I am using the WebAPI Versioning package to version my API by the X-Api-Header by using the "VersionHeaderVersionedControllerSelector". I am also using the Microsoft.AspNet.WebApi.HelpPage to ...
6
votes
2answers
2k views
The inner handler has not been assigned using WebApi Delegating handler
I have got a problem with WebApi throwing an exception here in my code:
public class WebApiAuthenticationHandler : DelegatingHandler
{
private const string AuthToken = "AUTH-TOKEN";
...
6
votes
1answer
13k views
Custom httphandler and routehandler with ASPNET MVC 4 and webapi
I'm working on an ASPNET MVC 4 and WebApi. The webapi methods will be consumed by mobile devices. We need to secure the services and what we are using is to encrypt the data in some particular way.
...
6
votes
1answer
274 views
HttpRouteBuilder - Where did it go and Why?
I upgraded my nuget package for the Web API 2 from the RC1 to 5.0.0, and was dumbfounded to find that HttpRouteBuilder, which used to be accessible, was made internal. Along with that, there is no ...
5
votes
1answer
985 views
AttributeRouting not working with HttpConfiguration object for writing Integration tests
I'm creating some integration tests following the ideas outlined here:
http://www.strathweb.com/2012/06/asp-net-web-api-integration-testing-with-in-memory-hosting/
When I try to register routes from ...
5
votes
1answer
3k views
No type was found that matches the controller named 'User'
I'm trying to navigate to a page which its URL is in the following format:
localhost:xxxxx/User/{id}/VerifyEmail?secretKey=xxxxxxxxxxxxxxx
I've added a new route in the RouteConfig.cs file and so my ...
5
votes
3answers
730 views
WebApi Multiple actions were found with GetAll() and GetByIds(int[] ids)
Using the standard route:
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = ...
5
votes
1answer
385 views
.Net Web API Routing & Help Page
I am struggling to get the API help page to show all my API endpoints, and to show them in the style I want.
Here are my routes:
config.Routes.MapHttpRoute("Orgs", "v1/Orgs/{orgId}",
new { ...
5
votes
2answers
791 views
WebAPI 2 attribute routing enable session state
We figured out how to enable session state with webapi Sample here
Now we have WebApi 2 attribute routing, so we no longer have route object to inject custom handler.
Is there any way of enabling ...
4
votes
4answers
10k views
Routing based on query string parameter name
I'm trying to configure routing in my MVC4 WebAPI project.
I want to be able to search for products based on their name or their type like so:
/api/products?name=WidgetX - returns all products named ...
4
votes
1answer
4k views
Web API 2 / MVC 5 : Attribute Routing passing parameters as querystring to target different actions on same controller
I've been playing with the new Web API 2 (which looks very promising btw) but I'm having a bit of a headache to get some routes working.
All works fine when I have GetAllUsers / GetUser(int id), but ...
4
votes
1answer
529 views
Web API nested routing not working as expected
I am having difficulty with a nested Web API routing set-up.
Given a routing config of:
config.Routes.MapHttpRoute(
name: "UsersGroups",
routeTemplate: ...
4
votes
2answers
80 views
Is there a default verb applied to a Web API ApiController method?
I've been looking at the code (in https://github.com/patelsan/WebAPIAuthentication) from this article: http://www.codeproject.com/Articles/630986/Cross-Platform-Authentication-With-ASP-NET-Web-API.
...
4
votes
5answers
925 views
Prevent Web API method from being called
I am working on creating a Web API using ASP.NET Web API. I'm currently stubbing out functionality on my endpoints so that I can then start developing against it.
My WebApiConfig.cs file looks like ...
4
votes
2answers
586 views
New WebApi Project doesn't have default routing for API (but still works)
I've created a new WebAPI MVC project, the API controllers have the path http://localhost:1234/api and they work from this route, but the RegisterRoutes class doesn't contain a default routing, it ...
4
votes
1answer
3k views
Web API 2 routing attributes not working
I'm using the final release versions of .NET 4.5 and Web API 2 (in Visual Studio 2013). I've been using this documentation as a reference, to no avail.
I have a few base routes like
api/providers
...
4
votes
1answer
2k views
Asp.net Web API: No action was found on the controller
So this has really been causing me a headache.
Route:
config.routes.MapHttpRoute(
name: 'ControllerAction' ,
routeTemplate: "api/{controller}/{action}"
...
3
votes
2answers
3k views
Asp.Net MVC4 + Web API Controller Delete request >> 404 error
I have a VS2012 MVC4 solution where I test Web API Controllers.
I successfully tested the GET, POST, PUT but the DELETE still got me an http 404 error. When I set a breakpoint in my 'DeleteMovie' ...
3
votes
2answers
6k views
Web API route to action name
I need a controller to return JSON to be consumed by JavaScript so I inherited from the ApiController class but it isn't behaving as I expected. The Apress book Pro ASP.NET MVC 4 and most of the ...
3
votes
2answers
2k views
Web API get route values
Is there any way to statically get route values from a service method (outside of a controller) that is running in a Web API context? For example, I can do the following in ASP.NET MVC:
var ...
3
votes
2answers
25 views
How can I safely handle invalid requests for repository data?
With this code:
public String Get(int id)
{
return platypi.Find(p => p.Id == id).Name;
}
...I can get existing data via:
http://localhost:33181/api/DPlatypus/N
(where N corresponds to ...
3
votes
1answer
525 views
ASP.NET WebAPI Supported Media Types per Method
Given a method in a controller:
public class CustomerController : ApiController
{
[HttpGet]
public CustomerDto GetById([FromUri] int id)
{
.
.
return customerDto
...
3
votes
1answer
325 views
What is the benefit of adding “routes.MapMvcAttributeRoutes()” to RegisterRoutes()?
According to the article "What's New in ASP.NET MVC5", you must add this to your RegisterRoutes() method in order to use Attribute Routing:
routes.MapMvcAttributeRoutes();
...so that the method is ...
3
votes
2answers
2k views
ASP.NET MVC4 Web API Controller Stuck on One Route
I created a new ASP.NET MVC4 Web Api Project. In addition to the default ValuesController, I added another controller, ScenarioController. It has the exact same methods as ValuesController. But for ...
3
votes
1answer
101 views
Attribute based webapi2 routing returns 404 for some methods
I'm presently working on a project that has been upgraded to Webapi2 from Webapi. Part of the conversion includes the switch to using attribute based routing.
I've appropriately setup my routes in ...
3
votes
1answer
75 views
Where is the “magic” happening when a Controller instantiates the correct implementation of the Interface in Web API DI?
It seems to me that somewhere a rabbit is being pulled out of a hat when it comes to DI in Web API Controllers.
I grok that:
0) The Controller in a Web API project can be called with various classes ...
3
votes
3answers
327 views
How can I call different GET Methods in the same Controller utilizing different parameters?
I have a Controller that contains two different Get methods. One takes an int value, while the other takes a String value, like below:
public class AccountController : ApiController
{
public ...
3
votes
2answers
353 views
Is there a way to tell routing that my default action name is equal to the HTTP Action Verb?
I've looked through this document on MSDN and can't come up with the answer.
Considering that I have a route defined like this:
config.Routes.MapHttpRoute(
name: ...
3
votes
1answer
6k views
Actions and QueryString parameters in Web API
I want to have my generic route determine if a query string was passed in the Url like this
http://localhost/query/DailyLogs/1?dateOfLog='1/13/2013'
Here is my current Route definition:
...
3
votes
1answer
1k views
UriPathExtensionMapping to control response format in WebAPI
I'm having a problem getting UriPathExtensionMapping working in ASP.NET WebAPI. My setup is as follows:
My routes are:
config.Routes.MapHttpRoute(
name: "Api ...
3
votes
2answers
3k views
How to ignore a route in MVC4 WebAPI configuration?
I have an MVC4 project with elmah added. My global.asax's Application_Start() has
WebApiConfig.Register(GlobalConfiguration.Configuration); // #1
...
3
votes
1answer
110 views
Can I set my WebAPI route to require that either parameter X or parameter Y is included?
For the GET function in my controller I want to require that a name be passed in. For the PUT function I want to require that the id be passed in (with the object in the message body). For example:
...
3
votes
2answers
309 views
Multiple view for multiple devices in ASP .Net MVC
What can be the best way for architecting an ASP .Net MVC project, which have common web service part and multiple views for multiple devices. I have started with a JQuery mobile project, and have ...
3
votes
1answer
961 views
Migrating from mvc4 to mvc5, attribute routing do not work
I have a asp.net mvc4/webapi using SimpleMembershipProvider that I'm trying to update to mvc5/webapi2 with the new asp.net Identity. I updated all assemblies, remove the obsolete ones, deleted my old ...
3
votes
1answer
659 views
Web API Help Pages - Order controllers by route prefix
Since areas are not easily supported in Web API (and also because I need more flexibility than project-wide routing rules), I am using the [RoutePrefix] attribute on my controllers to group my Web API ...
3
votes
2answers
1k views
File upload form with MVC4 Web-API: Getting Error 101 (net::ERR_CONNECTION_RESET): The connection was reset. Error
I'm getting a webpage not available error when trying to access a controller action in an MVC4 Web-API app with VS2010. I am trying to upload a small sized (less than 1MB) pdf document, create a ...
3
votes
1answer
255 views
BeginRouteForm doesn't work with API routes?
I have a form I'm trying to create with relatively simple code:
@using (Ajax.BeginRouteForm("DefaultApi", new { controller = "persons" }, new AjaxOptions {HttpMethod = "post", OnSuccess = ...
2
votes
2answers
177 views
Catch routing errors
I'm building a RESTful API and I would like to control all possible output to my consumers. I'm implementing an ExceptionFilterAttribute to filter all exceptions raised in my controllers. This, ...
2
votes
1answer
1k views
ASP.NET Web Api 2 - Subdomain Attribute Routing
I've been using AttributeRouting for quite some time in my MVC application. However, one thing it always lacked is subdomain routing in Web Api (among other features in that library that work with MVC ...
2
votes
1answer
2k views
.Net WebApi OData Actions that return an Queryable
I want to achieve something close to the RateProduct action described in: http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api/odata-actions
In that tutorial it is defined as:
...
2
votes
3answers
1k views
Web Api 2 global route prefix for route attributes?
I'd like to expose a company's api by two ways:
api.company.com (pure WebApi web site)
company.com/api (add WebApi to existing MVC5 company site)
So, I placed models/controllers in a separate ...
2
votes
4answers
1k views
A route named 'DefaultApi' is already in the route collection
This question may seems duplicate but this is slightly different.
In all other question in SO I had noticed that they have multiple routes registered. but in my case I have just one route.
I am ...
2
votes
4answers
3k views
Web API routing actions
The goal is to allow these four endpoints:
POST v1/invoices<br/>
POST v1/invoices/12345<br/>
POST v1/invoices/12345/attachment<br/>
POST v1/invoices/12345/image
...