Questions tagged [asp.net-web-api2]

ASP.NET Web API 2 is a framework for building HTTP services for clients like browsers and mobile devices. It is based on the Microsoft .NET Framework and an ideal choice for building RESTful services.

Web API 2 now includes annotation-based routing.

Developers can assign custom paths to Methods in Web API 2 Controllers. This greatly extends the versatility of Web API, as the original was limited to having 4 methods for each Controller (Get, Post, Put, Delete).

7708 questions
362
votes
32 answers

No connection could be made because the target machine actively refused it?

Sometimes I get the following error while I was doing HttpWebRequest to a WebService. I copied my code below too. System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: No connection could be made…
hsnkvk
  • 3,629
  • 2
  • 16
  • 4
242
votes
31 answers

Swagger UI Web Api documentation Present enums as strings?

Is there a way to display all enums as their string value in swagger instead of their int value? I want to be able to submit POST actions and put enums according to their string value without having to look at the enum every time. I tried…
user5326354
162
votes
6 answers

CORS: credentials mode is 'include'

Yes, I know what you are thinking - yet another CORS question, but this time I'm stumped. So to start off, the actual error message: XMLHttpRequest cannot load http://localhost/Foo.API/token. The value of the 'Access-Control-Allow-Origin' header in…
Richard Bailey
  • 2,658
  • 4
  • 27
  • 45
147
votes
6 answers

How do I unit test web api action method when it returns IHttpActionResult?

Let's assume this is my action method public IHttpActionResult Get(int id) { var status = GetSomething(id); if (status) { return Ok(); } else { return NotFound(); } } Test will be var httpActionResult =…
sunil
  • 5,078
  • 6
  • 28
  • 33
137
votes
4 answers

How to implement oauth2 server in ASP.NET MVC 5 and WEB API 2

First I'll sketch my project: For my internship I need to add functionality to an existing system. A 3rd party client must be able to access data from AX Webservices once he is authorised by the user via OAuth2. I understand that I need to make a…
Robin
  • 2,704
  • 7
  • 30
  • 47
130
votes
2 answers

Where can I find a NuGet package for upgrading to System.Web.Http v5.0.0.0?

Just upgraded an ASP.NET MVC4 project to use Unity.WebApi version 5.0.0.0 and it requires System.Web.Http v 5.0.0.0 as per the following error: Assembly 'Unity.WebApi, Version=5.1.0.0, Culture=neutral, PublicKeyToken=43da31bc42a85347' uses…
Klaus Nji
  • 18,107
  • 29
  • 105
  • 185
119
votes
9 answers

Dot character '.' in MVC Web API 2 for request such as api/people/STAFF.45287

The URL I'm trying to let work is one in the style of: http://somedomain.com/api/people/staff.33311 (just like sites as LAST.FM allow all sort of signs in their RESTFul & WebPage urls, for example "http://www.last.fm/artist/psy'aviah" is a valid url…
115
votes
9 answers

Web API 2: how to return JSON with camelCased property names, on objects and their sub-objects

UPDATE Thanks for all the answers. I am on a new project and it looks like I've finally got to the bottom of this: It looks like the following code was in fact to blame: public static HttpResponseMessage GetHttpSuccessResponse(object response,…
Tom
  • 7,994
  • 8
  • 45
  • 62
108
votes
7 answers

swagger error: Conflicting schemaIds: Duplicate schemaIds detected for types A and B

Using Web API and using swashbuckle to generate swagger documentation, I defined two different classes with the same name in two different namespaces. when I open swagger page in my browser it says Conflicting schemaIds: Duplicate schemaIds…
Mahdi Ataollahi
  • 4,544
  • 4
  • 30
  • 38
88
votes
16 answers

How to get base URL in Web API controller?

I know that I can use Url.Link() to get URL of a specific route, but how can I get Web API base URL in Web API controller?
Nikolai Samteladze
  • 7,699
  • 6
  • 44
  • 70
87
votes
17 answers

FromBody string parameter is giving null

This is probably something very basic, but I am having trouble figuring out where I am going wrong. I am trying to grab a string from the body of a POST, but "jsonString" only shows as null. I also want to avoid using a model, but maybe this isn't…
86
votes
11 answers

Asp.Net WebApi2 Enable CORS not working with AspNet.WebApi.Cors 5.2.3

I tried to follow the steps at http://enable-cors.org/server_aspnet.html to have my RESTful API (implemented with ASP.NET WebAPI2) work with cross origin requests (CORS Enabled). It's not working unless I modify the web.config. I installed WebApi…
diegosasw
  • 13,734
  • 16
  • 95
  • 159
81
votes
4 answers

Web API optional parameters

I have a controller with the following signature: [Route("products/filter/{apc=apc}/{xpc=xpc}/{sku=sku}")] public IHttpActionResult Get(string apc, string xpc, int? sku) { ... } I call this method with following…
Josh
  • 8,219
  • 13
  • 76
  • 123
77
votes
13 answers

An assembly specified in the application dependencies manifest (...) was not found

I upgraded Microsoft.AspNetCore from 2.0.3 to 2.0.5 and my WebAPI project, although running successfully locally, fails to start in production (IIS). Everything was fine in production until this upgrade. The error message produced in the log…
KSwift87
  • 1,843
  • 5
  • 23
  • 40
75
votes
1 answer

Registering Web API 2 external logins from multiple API clients with OWIN Identity

I would like the following architecture (I've made up the product name for this example): Web API 2 application running on one server http://api.prettypictures.com MVC 5 client app running on another server http://www.webpics.com I would like…
joshcomley
  • 28,099
  • 24
  • 107
  • 147
1
2 3
99 100