Pass multiple complex objects to a post/put Web API method

In the current version of Web API, the usage of multiple complex objects (like your Content and Config complex objects) within the Web API method signature is not allowed. I’m betting good money that config (your second parameter) is always coming back as NULL. This is because only one complex object can be parsed from … Read more

Order of execution with multiple filters in web api

Some things to note here: Filters get executed in the following order for an action: Globally Defined Filters -> Controller-specific Filters -> Action-specific Filters. Authorization Filters -> Action Filters -> Exception Filters Now the problem that you seem to mention is related to having multiple filters of the same kind (ex: Multiple ActionFilterAttribute decorated on … Read more

Deserializing JToken content to an Object

You can use JToken.ToObject generic method. http://www.nudoq.org/#!/Packages/Newtonsoft.Json/Newtonsoft.Json/JToken/M/ToObject(T) Server API Code: public void Test(JToken users) { var usersArray = users.ToObject<User[]>(); } Here is the client code I use. string json = “[{\”UserId\”:0,\”Username\”:\”jj.stranger\”,\”FirstName\”:\”JJ\”,\”LastName\”:\”stranger\”}]”; HttpClient client = new HttpClient(); var result = client.PostAsync(@”http://localhost:50577/api/values/test”, new StringContent(json, Encoding.UTF8, “application/json”)).Result; The object gets converted to Users array without any issues.

HTTP 415 unsupported media type error when calling Web API 2 endpoint

SOLVED After banging my head on the wall for a couple days with this issue, it was looking like the problem had something to do with the content type negotiation between the client and server. I dug deeper into that using Fiddler to check the request details coming from the client app, here’s a screenshot … Read more

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

You can add as many claims as you want. You can add the standard set of claims from System.Security.Claims or create your own. Claims will be encrypted in your token so they will only be accessed from the resource server. If you want your client to be able to read extended properties of your token … Read more

OWIN HttpListener not located

You have to include Microsoft.Owin.Host.HttpListener.dll in your project references. You can add it through NuGet. However, if the code executing: WebApp.Start<SrvcHst> (…); is contained within a class library, make sure that the executable consuming the library also includes the reference to Microsoft.Owin.Host.HttpListener.dll, or else it would not get deployed with your program, as there are … Read more

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

Update: things have changed since I wrote this post in January: MSFT released their official OpenID connect client middleware and I worked hard with @manfredsteyer to adapt the OAuth2 authorization server built in Katana to OpenID connect. This combination results in a far easier and far more powerful solution that doesn’t require any custom client … Read more

Web API optional parameters

I figured it out. I was using a bad example I found in the past of how to map query string to the method parameters. In case anyone else needs it, in order to have optional parameters in a query string such as: ~/api/products/filter?apc=AA&xpc=BB ~/api/products/filter?sku=7199123 you would use: [Route(“products/filter/{apc?}/{xpc?}/{sku?}”)] public IHttpActionResult Get(string apc = null, … Read more

FromBody string parameter is giving null

By declaring the jsonString parameter with [FromBody] you tell ASP.NET Core to use the input formatter to bind the provided JSON (or XML) to a model. So your test should work, if you provide a simple model class public class MyModel { public string Key {get; set;} } [Route(“Edit/Test”)] [HttpPost] public void Test(int id, [FromBody] … Read more

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