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

I’ve created a pared-down demo project for you. Source: https://github.com/bigfont/webapi-cors Api Link: https://cors-webapi.azurewebsites.net/api/values You can try the above API Link from your local Fiddler to see the headers. Here is an explanation. Global.ascx All this does is call the WebApiConfig. It’s nothing but code organization. public class WebApiApplication : System.Web.HttpApplication { protected void Application_Start() { … Read more

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

Every class in the swagger JSON must have a unique schemaId. Swashbuckler tries to just use the class name as a simple schemaId, however if you have two classes in different namespaces with the same name (as you do) this will not work. As the error suggests, you can use the config setting “UseFullTypeNameInSchemaIds*” for … Read more

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

Putting it all together you get… protected void Application_Start() { HttpConfiguration config = GlobalConfiguration.Configuration; config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); config.Formatters.JsonFormatter.UseDataContractJsonSerializer = false; }

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

You need the Microsoft.AspNet.WebApi.Core package. You can see it in the .csproj file: <Reference Include=”System.Web.Http, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL”> <SpecificVersion>False</SpecificVersion> <HintPath>..\packages\Microsoft.AspNet.WebApi.Core.5.0.0\lib\net45\System.Web.Http.dll</HintPath> </Reference>

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

There is a brilliant blog post from Taiseer Joudeh with a detailed step-by-step description. Part 1: Token Based Authentication using ASP.NET Web API 2, Owin, and Identity Part 2: AngularJS Token Authentication using ASP.NET Web API 2, Owin, and Identity Part 3: Enable OAuth Refresh Tokens in AngularJS App using ASP .NET Web API 2, … Read more

CORS: credentials mode is ‘include’

The issue stems from your Angular code: When withCredentials is set to true, it is trying to send credentials or cookies along with the request. As that means another origin is potentially trying to do authenticated requests, the wildcard (“*”) is not permitted as the “Access-Control-Allow-Origin” header. You would have to explicitly respond with the … Read more

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

Here Ok() is just a helper for the type OkResult which sets the response status to be HttpStatusCode.Ok…so you can just check if the instance of your action result is an OkResult…some examples(written in XUnit): // if your action returns: NotFound() IHttpActionResult actionResult = valuesController.Get(10); Assert.IsType<NotFoundResult>(actionResult); // if your action returns: Ok() actionResult = valuesController.Get(11); … Read more

Swagger UI Web Api documentation Present enums as strings?

Enable globally From the docs: httpConfiguration .EnableSwagger(c => { c.SingleApiVersion(“v1”, “A title for your API”); c.DescribeAllEnumsAsStrings(); // this will do the trick }); Enum/string conversion on particular property Also, if you want this behavior only on a particular type and property, use the StringEnumConverter: public class Letter { [Required] public string Content {get; set;} [Required] … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)