OData V4 modify $filter on server side

Remove [EnableQuery] attribute, your scenario should work, because after using this attribute, OData/WebApi will apply your original query option after you return data in controller, if you already apply in your controller method, then you shouldn’t use that attribute. But if your query option contains $select, those code are not working because the result’s type … Read more

Adding a custom query backed Navigation Property to ODataConventionModelBuilder

You have to call “AddNavigationTarget” on the EntitySet. Assume that your namespace is “MyNamespace”, then add the following code to your WebApiConfig.cs. In this way, retrieving the data with “Get: odata/Cars(1)/Parts” will work. var cars = (EdmEntitySet)edmModel.EntityContainers().Single().FindEntitySet(“Cars”); var parts = (EdmEntitySet)edmModel.EntityContainers().Single().FindEntitySet(“Parts”); var carType = (EdmEntityType)edmModel.FindDeclaredType(“MyNamespace.Car”); var partType = (EdmEntityType)edmModel.FindDeclaredType(“MyNamespace.Part”); var partsProperty = new EdmNavigationPropertyInfo(); partsProperty.TargetMultiplicity … Read more

Asp.net core MVC post parameter always null

This could be because of how the null values are being handled. Set NullValueHandling to Ignore in AddJsonOptions and see if that works. public void ConfigureServices(IServiceCollection services) { services .AddMvc() .AddJsonOptions(jsonOptions=> { jsonOptions.SerializerSettings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore; }); }

Get Content-Disposition parameters

If you are working with .NET 4.5 or later, consider using the System.Net.Mime.ContentDisposition class: string cpString = wc.ResponseHeaders[“Content-Disposition”]; ContentDisposition contentDisposition = new ContentDisposition(cpString); string filename = contentDisposition.FileName; StringDictionary parameters = contentDisposition.Parameters; // You have got parameters now Edit: otherwise, you need to parse Content-Disposition header according to it’s specification. Here is a simple class that … Read more

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

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

ionic app cannot connect cors enabled server with $http

cordova-plugin-whitelist seems to be “mandatory” at present. install it : cordova plugin add cordova-plugin-whitelist configure config.xml You can keep your current setup with * or change for more restrictive rules add a html policy on index.html, you shall add a Policy also. To authorise everything, here it is : <meta http-equiv=”Content-Security-Policy” content=”default-src *; style-src ‘self’ … Read more

Web API and OData- Pass Multiple Parameters

You can define a function import named GetReports that has two parameters. (Note: the name of the function import can’t be the same with entity set name) Configure your EDM model as: var builder = new ODataConventionModelBuilder(); builder.EntitySet<Report>(“Reports”); var function = builder.Function(“GetReports”); function.Parameter<int>(“Id”); function.Parameter<int>(“Year”); function.ReturnsCollectionFromEntitySet<Report>(“Reports”); var model = builder.GetEdmModel(); And then write your method as: … Read more