tagged [asp.net-web-api2]

Response to preflight request doesn't pass access control check (Angular2)

Response to preflight request doesn't pass access control check (Angular2) I am getting below error on call to REST Web API in Asp.net. [http://localhost:54859/api/PostData](http://localhost:54859/api...

HttpClient Headers vs HttpRequestMessage Headers

HttpClient Headers vs HttpRequestMessage Headers When should we use headers in the HttpRequestMessage object over headers in the HttpClient ?? We have need to add Authorization (always changing) and f...

Web API POST parameter is null for large JSON request

Web API POST parameter is null for large JSON request I have a POST method in Web API controller that takes a class with 50 fields as parameter. I am getting the parameter value as `null` in the contr...

22 Dec at 03:16

Unable to get request header in asp net core web API

Unable to get request header in asp net core web API I am trying to create a custom filter in asp net core web api which is as below but unable to get header info. ``` internal class BasicAuthFilterAt...

21 Feb at 08:28

WebAPI HttpActionExecutedContext get controller name

WebAPI HttpActionExecutedContext get controller name I need to get the controller who triggers a filter attribute. I have the following filter: ``` public override void OnException(HttpActionExecutedC...

8 Jul at 02:11

Visual Studio 2017 Localization Publish Settings

Visual Studio 2017 Localization Publish Settings This should be simple, but I haven't found a way to make this stop happening. Visual Studio publishes a lot of localized DLLs - It appears there is Ger...

CS0433: Ambiguous Reference System.Net.Http.HttpRequestMessageExtensions

CS0433: Ambiguous Reference System.Net.Http.HttpRequestMessageExtensions I am using VS2015 with Resharper for WebAPI 2.0 project. Trying to use System.Net.Http.HttpRequestMessageExtensions.GetRequestC...

How to return JSON in an ApiController for a single method?

How to return JSON in an ApiController for a single method? Currently, my `ApiController`s are returning XML as a response, but for a single method, I want to return JSON. i.e. I can't make a global c...

WebApi 2 POST with single string parameter not working

WebApi 2 POST with single string parameter not working I have the following controller: WebApi config ``` config.Routes.MapHttpRoute( name:

How to generate JSON Postman Collections from a WebApi2 project using WebApi HelpPages that are suitable for import

How to generate JSON Postman Collections from a WebApi2 project using WebApi HelpPages that are suitable for import [Postman](http://www.getpostman.com) is a tool that can be used to easily test restf...

How to change default Web API 2 to JSON formatter?

How to change default Web API 2 to JSON formatter? I have a Web API project that returns some product data. It negotiates the return type correctly depending on the Accept header (JSON/XML) of the req...

10 Aug at 02:32

How to catch all exceptions in Web API 2?

How to catch all exceptions in Web API 2? I'm writing a RESTful API in Web API and I'm not sure how to handle errors effectively. I want the API to return JSON, and it needs to consist of the exact sa...

20 Aug at 01:25

Pass decimal as value in WebAPI 2 URL

Pass decimal as value in WebAPI 2 URL I am creating a Web Api (v2.0) Method that needs to take in a decimal value as its parameter. I am getting a 404 not found error if I use the following URL: But i...

Unit testing a WebAPI2 controller method with a header value

Unit testing a WebAPI2 controller method with a header value I'd like to "unit" test a method on my WebAPI contoller. This method relies on a header being sent with it. So needs to have a value in the...

Web API optional parameters

Web API optional parameters I have a controller with the following signature: I call this method with following URIs: - - The first URI works without issue. The second one has a strange side effect. E...

OWIN HttpListener not located

OWIN HttpListener not located When I try to start : I get the following exception. What could be the root cause? ``` System.MissingMemberException was caught HResult=-2146233070 Message=The server f...

EntityFramework with WEB API, update all properties

EntityFramework with WEB API, update all properties I'm using EF with WEB API. I have a PUT Method which updates a entity which already is in the db. Right now I have this: ``` // PUT api/fleet/5 ...

FluentValidation modify error message in Must function

FluentValidation modify error message in Must function Inside class that is responsible for validation I have simple rule: and below is my `ValidateId` function: ``` private bool ValidateId(CreateAcco...

19 Jul at 09:32

Multiple Dtos for same entity

Multiple Dtos for same entity Is it a good practice to use multiple DTO's for same entity in different API endpoints. For example: I have a api endpoint which accpets the following Dto: ``` public cla...

18 Nov at 14:19

Method not found: 'System.String System.String.Format(System.IFormatProvider, System.String, System.Object)

Method not found: 'System.String System.String.Format(System.IFormatProvider, System.String, System.Object) I have a Web API 2 project with help pages that runs fine locally but throws this error when...

21 Nov at 13:53

Order of execution with multiple filters in web api

Order of execution with multiple filters in web api I am using latest `web api`. I do annotate controllers with 3 different filter attributes. I can not be sure that the filters run in the order they ...

Web API 2 download file using async Task<IHttpActionResult>

Web API 2 download file using async Task I need to write a method like below to return a text document (.txt, pdf, .doc, .docx etc) While there are good examples of posting file in Web API 2.0 on the ...

24 Feb at 13:29

How do I remove headers from my Web API response?

How do I remove headers from my Web API response? New Web API 2.0 project so we have full control over the entire request / response pipeline. How do we remove the "X-" headers from a response sent by...

Deserializing JToken content to an Object

Deserializing JToken content to an Object I want to deserialize JToken content to an object (`User`). How am I able to do this? This being sent to an api parameter as `JToken`. ``` public class user {...

Load JSON string to HttpRequestMessage

Load JSON string to HttpRequestMessage I'm writing some tests for my WebAPI web service and cannot figure out how to send JSON to my service method in the test. ``` ScheduleRequest sr = new ScheduleRe...

22 Aug at 21:28