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).

7629 questions
294
votes
29 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
  • 2,949
  • 2
  • 13
  • 4
146
votes
22 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
140
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
  • 4,858
  • 6
  • 25
  • 33
132
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,569
  • 7
  • 25
  • 46
126
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
  • 15,695
  • 23
  • 96
  • 171
111
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…
Richard Bailey
  • 2,109
  • 3
  • 20
  • 44
110
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…
108
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,474
  • 7
  • 40
  • 56
80
votes
6 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…
78
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,337
  • 4
  • 41
  • 70
77
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
  • 8,724
  • 7
  • 66
  • 106
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
  • 26,135
  • 21
  • 102
  • 140
72
votes
4 answers

OWIN HttpListener not located

When I try to start : WebApp.Start(new StartOptions { Port = 9956, ServerFactory = "Microsoft.Owin.Host.HttpListener" }); I get the following exception. What could be the root cause? System.MissingMemberException was caught …
GilliVilla
  • 4,596
  • 10
  • 50
  • 85
63
votes
2 answers

Return more info to the client using OAuth Bearer Tokens Generation and Owin in WebApi

I have created a WebApi and a Cordova application. I am using HTTP requests to communicate between the Cordova application and the WebAPI. In the WebAPI, I've implemented OAuth Bearer Token Generation. public void ConfigureOAuth(IAppBuilder app) …
Ivan Stoyanov
  • 5,072
  • 10
  • 52
  • 68
62
votes
14 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…
1
2 3
99 100