asp.net-web-api2

Autofac WebApi 2 OWIN Not Working

戏子无情 提交于 2019-12-10 10:37:25
问题 Having an issue with Autofac and WebApi2 using OWIN. Basically the Constructor isn't getting Injected. public class Startup { public void Configuration(IAppBuilder app) { var config = new HttpConfiguration(); config.MapHttpAttributeRoutes(); config.Routes.MapHttpRoute( name: "Default Route", routeTemplate: "{controller}.{ext}" ); config.Routes.MapHttpRoute( name: "Default Route with Id", routeTemplate: "{controller}/{id}.{ext}", defaults: new { id = RouteParameter.Optional } ); var builder =

MVC Web API: dot in URL parameter value

我是研究僧i 提交于 2019-12-10 10:35:58
问题 I have implemented search functionality to look for data with a (part of a) code as search criteria, which includes a . (dot) in the value, so it should be possible to include that in the search criteria. Consider url: myhost/api/search/88. Out of the box, without doing anything extra, that will result in a 404 error. While, not surprisingly, the url works fine if I remove the dot. I found this as possible answer on StackOverflow: <system.web> <httpRuntime relaxedUrlToFileSystemMapping="true"

Newtonsoft.json IsoDateTimeConverter and DateFormatHandling

烈酒焚心 提交于 2019-12-10 09:59:08
问题 This is not an issue but concept I just want to make it clear. When working with asp.net web api we use Newtonsoft.Json's SerializerSettings . In this setting we can set jsonSetting.Converters.Add(new IsoDateTimeConverter()); jsonSetting.DateFormatHandling = DateFormatHandling.IsoDateFormat; I understood what IsoDateTimeConverter is doing but but not clear about DateFormatHandling.IsoDateFormat . It seems to be there is no effect of DateFormatHandling.MicrosoftDateFormat if you still using

ASP.NET Web API - OWIN - TokenEndPointPath not working in IIS

一笑奈何 提交于 2019-12-10 05:43:38
问题 I have the following code in my startup.cs. Setting up the TokenEndpointPath works perfectly in IIS Express and when the Web API project is deployed to the root of a website in IIS. However, if I host in a nested application (i.e. an application within a website) in IIS calls to the token endpoint result in a 404. Is there a way to base the TokenEndpointPath off of the actual IIS structure instead of the root, as it does here? Right now: This Works http://server:80/api/token This does not

405 Method Not Allowed Web API 2

て烟熏妆下的殇ゞ 提交于 2019-12-10 05:38:41
问题 I've been through just about every article I can find, on SO and more. I've made changes to the Web.config to meet the answers as they all seem to point to removing the WebDAV module and handler. However, I'm still getting the error: 405 Method Not Allowed The requested resource does not support http method 'PUT'. NOTE: this was originally just an MVC 4 project. I've added artifacts to support Web API. Seems like it's possible I may have missed something. NOTE: the GET calls are working just

Identity Authorize Attribute Roles with Web API

百般思念 提交于 2019-12-10 03:09:17
问题 I have a small Web API application that uses Identity to manage users using Owin Bearer Tokens. The basics of this implementation work fine: I can register a user, login a user and access Web API end points that are marked with [Authorize] . My next step is to limit Web API endpoints using roles. For example, a controller that only users in the Admin role can access. I've created the Admin user as below and I add them to the Admin role. However when I update my existing controllers from

WebAPi - unify error messages format from ApiController and OAuthAuthorizationServerProvider

会有一股神秘感。 提交于 2019-12-10 00:40:15
问题 In my WebAPI project I'm using Owin.Security.OAuth to add JWT authentication. Inside GrantResourceOwnerCredentials of my OAuthProvider I'm setting errors using below line: context.SetError("invalid_grant", "Account locked."); this is returned to client as: { "error": "invalid_grant", "error_description": "Account locked." } after user gets authenticated and he tries to do "normal" request to one of my controllers he gets below response when model is invalid (using FluentValidation): {

Response for preflight has invalid HTTP status code 404 - Angular 4 and Web API 2

拈花ヽ惹草 提交于 2019-12-10 00:24:59
问题 In the service I am calling Web API(2)(hosted on different server than the front end angular 4 application) action method in order to retrieve some info. The action method needs authorization which I am doing using access token that I receive after logging into the application. Now, the code works fine in Microsoft edge, however gives me preflight error in chrome which I guess is CORS issue. Not sure how to resolve this. Can someone help me with this? Here is my code; getCompanyInfo(id:

How to create a “sub-resource” using OData without creating a collection property for it?

冷暖自知 提交于 2019-12-09 20:21:45
问题 I'm creating a Web API 2 using OData v4 to provide the following HTTP verbs for my models: GET , POST and PUT , which means that for each resource (model class) I can insert/update/retrieve data from the following URLs: /api/myResourceName /api/myResourceName/{id} And for my sub-resources (the children models) I can do the same through the following URLs: /api/myResourceName/{id}/subresource /api/myResourceName/{id}/subresource/{subresourceId} However, in order to have a sub-resource, I

ASP.NET Web API 2 and partial updates

本小妞迷上赌 提交于 2019-12-09 18:15:08
问题 We are using ASP.NET Web API 2 and want to expose ability to partially edit some object in the following fashion: HTTP PATCH /customers/1 { "firstName": "John", "lastName": null } ... to set firstName to "John" and lastName to null . HTTP PATCH /customers/1 { "firstName": "John" } ... in order just to update firstName to "John" and do not touch lastName at all. Suppose we have a lot of properties that we want to update with such semantic. This is quite convenient behavior that is exercised by