asp.net-web-api2

The 'DelegatingHandler' list is invalid because the property 'InnerHandler' of 'handler' is not null

自古美人都是妖i 提交于 2019-12-04 16:02:08
I have a custom message handler that I add globally as follows: public class CustomerHandler : DelegatingHandler { public CustomHandler(HttpConfiguration httpConfiguration) { InnerHandler = new HttpControllerDispatcher(httpConfiguration); } } config.MessageHandlers.Add(new CustomHandler(config)); However, I get the following error: The 'DelegatingHandler' list is invalid because the property 'InnerHandler' of 'CustomHandler' is not null. Parametername: handlers So I changed the code to: config.MessageHandlers.Add(new CustomHandler(config) { InnerHandler = null }); And I get an error:

ASP.NET Web API multiple RoutePrefix

为君一笑 提交于 2019-12-04 15:59:59
问题 The opensource Attribute Routing allows to have multiple route-prefixes. Why does ASP.NET Web API 2.0 does not allow to have multiple RoutePrefix(). [RoutePrefix("api/v1/{abc}/Entity")] [RoutePrefix("api/v1/{abc}/{xyz?}/Entity")] public class MyApiController : ApiController { [Route("")] public IHttpResult Get() { return Ok("Hello World"); } } 回答1: You can add a route to the action method also overriding the RoutePrefix with a "~" example: [RoutePrefix("api/v1/{abc}/Entity")] public class

Implementing Forms authentication over async requests

送分小仙女□ 提交于 2019-12-04 15:28:05
In an angular app with a .net web api backend, I'm trying to implement forms authentication over async requests. Here is the relevant portion of my web.config... <authentication mode="Forms"> <forms loginUrl="/" cookieless="UseCookies" name=".TIMETRACK" requireSSL="false" timeout="30" protection="All" path="/TimeTrack" /> </authentication> Here is my web api login method... [Route("Login")] public HttpResponseMessage Post(AppUser credentials) { var userTemplate = _authenticationProvider.GetUserByEmail(credentials.Email); var user = Mapper.Map<ClientUser>(credentials); if (userTemplate.HashCode

Deserializing JToken content to an Object

会有一股神秘感。 提交于 2019-12-04 15:13:02
问题 I want to deserialize JToken content to an object ( User ). How am I able to do this? Here is my json string: string json = @"[{""UserId"":0,""Username"":""jj.stranger"",""FirstName"":""JJ"",""LastName"":""stranger""}]"; This being sent to an api parameter as JToken . User class: public class user { public int UserId {get; set;} public string Username {get; set;} public string FirstName {get; set;} public string LastName {get; set;} } Web Api Method: public IHttpActionResult Post([FromBody

Requests are queuing in Azure AppService though it has enough threads in threadpool

寵の児 提交于 2019-12-04 13:43:46
问题 I have written an api using asp.net webapi and deployed it in azure as Appservice. Name of my controller is TestController and My action method is something like bellow. [Route("Test/Get")] public string Get() { Thread.Sleep(10000); return "value"; } So for each request it should wait for 10 sec before return string "value". I have also written another endpoint to see the number of threads in threadpool working for executing requests. That action is something like bellow. [Route("Test

Request Token with JQuery from Web API

时光怂恿深爱的人放手 提交于 2019-12-04 12:57:28
问题 I'm doing an ajax-request in Javascript to obtain a JWT from my WebAPI AuthenticationProvider. This is my js-function: function authenticateUser(credentials) { var body = { grant_type: 'password', client_id: 'myClientId', client_secret: 'myClientSecret', username: credentials.name, password: credentials.password }; $.ajax({ url: 'http://localhost:9000/token', type: 'POST', dataType: 'json', contentType: 'application/x-www-form-urlencoded; charset=UTF-8', /* data: JSON.stringify(body), /*

Asp.net Identity, Generate WebApi token OAuthGrantResourceOwnerCredentialsContext - no access to UserManager using Unity

瘦欲@ 提交于 2019-12-04 12:15:17
I am trying to setup a project structure so that I have a WebApi, WebUI and Domain layer. I have moved all the Asp.Net.Identity objects into the Domain layer and have also setup the ApplicationContext here too (inheriting from IdentityContext). (I have used this tutorial and package as a base which is excellent. http://tech.trailmax.info/2014/09/aspnet-identity-and-ioc-container-registration/ ) In the WebAPI layer I am able to use the Account controller correctly to login and register. However, I cannot generate an access token. The OAuthGrantResourceOwnerCredentialsContext method internally

Authenticating against a webapi using azure b2c from an spa (angular and adal.js)

爱⌒轻易说出口 提交于 2019-12-04 11:44:33
问题 I'm trying to authenticate my SPA (angular.js and adal.js (similar to the https://github.com/Azure-Samples/active-directory-angularjs-singlepageapp-dotnet-webapi example) My AD is a azure b2c preview tenant. I can successfully log in to my webapi from my Website, but not from the JS SPA via angular. My Setup: Webapi and Website share the same clientid (does only seem to work this way) The SPA has its own clientid, because otherwise i get "api version not supported" errors when trying to log

JSON to Model property binding using JsonProperty

纵然是瞬间 提交于 2019-12-04 11:26:36
I'm bound by agreements between my party and the client to use json parameters containing dashes. Since it's not possible to use that in property names in C#, I need to map to the desired property. What I do now: The below code is simplified for convenience. Model public class MyRequest { [JsonProperty("request-number")] public string RequestNumber { get; set; } [JsonProperty("name")] public string Name { get; set; } } Controller [HttpGet] [Route("api/load-stuff")] public Stuff LoadStuff([FromUri]MyRequest request) { return BackEnd.LoadStuff(request); } Call to the API from client The above

How do I host/publish my .Net Core WebAPI on Ubuntu?

天大地大妈咪最大 提交于 2019-12-04 11:20:24
I am learning .Net Core. I have developed WebApplication using ASP.Net MVC and as it can be installed and run on Local IIS. What's the similar way to Host / Publish .Net Core WebApi in Ubuntu and Linux instead of running on specific port like 5000? Is docker helpful for that context? If yes then how can I use it? Is it possible to host / publish without docker? How can i Host / Publish without Docker? I also read following link and implemented all steps. Publish to a Linux Production Environment In above link i am unable to identify what will be the url to access webapi? As @Pawel has noted,