asp.net-web-api2

MVC5 Web API and Dependency Injection

天涯浪子 提交于 2020-06-12 07:15:11
问题 Trying to do some DI on Web API 2 without third-party tools. So, from some examples I've got custom dependency resolver (why there's no integrated one? Strange, even Microsoft.Extensions.DependencyInjection provides nothing): public class DependencyResolver : IDependencyResolver { protected IServiceProvider _serviceProvider; public DependencyResolver(IServiceProvider serviceProvider) { this._serviceProvider = serviceProvider; } public IDependencyScope BeginScope() { return this; } public void

MVC5 Web API and Dependency Injection

倾然丶 夕夏残阳落幕 提交于 2020-06-12 07:14:48
问题 Trying to do some DI on Web API 2 without third-party tools. So, from some examples I've got custom dependency resolver (why there's no integrated one? Strange, even Microsoft.Extensions.DependencyInjection provides nothing): public class DependencyResolver : IDependencyResolver { protected IServiceProvider _serviceProvider; public DependencyResolver(IServiceProvider serviceProvider) { this._serviceProvider = serviceProvider; } public IDependencyScope BeginScope() { return this; } public void

.NET Framework MVC and Web Api Auth JWT

倾然丶 夕夏残阳落幕 提交于 2020-06-11 18:39:27
问题 I have a project in MVC using .NET Framework v4.7 with some WebApi on it. What I need to know is how to use a middleware between then to authorize a JWT for HTTP requests and MVC Action requests. I've searched everywhere looking for a solution sample, but I couldn't find anything. If anyone could help, I would be grateful. Sorry for the English. 回答1: If I grasped your problem statement, I think OWIN might be an option: you decouple your application from underlying hosting and get an

.NET Framework MVC and Web Api Auth JWT

夙愿已清 提交于 2020-06-11 18:39:11
问题 I have a project in MVC using .NET Framework v4.7 with some WebApi on it. What I need to know is how to use a middleware between then to authorize a JWT for HTTP requests and MVC Action requests. I've searched everywhere looking for a solution sample, but I couldn't find anything. If anyone could help, I would be grateful. Sorry for the English. 回答1: If I grasped your problem statement, I think OWIN might be an option: you decouple your application from underlying hosting and get an

parallel.foreach and httpclient - strange behaviour

情到浓时终转凉″ 提交于 2020-05-26 03:57:52
问题 I have a piece of code that loops over a collection and calls httpclient for each iteration. The api that the httpclient calls, takes on average 30-40ms to execute. Calling it sequentially, I get the expected outcome, however as soon as I use Parallel.foreach, it takes longer. Looking closely in the logs, I can see quite a few httpclient calls take more 1000ms to execute and then the time drops back to 30-40ms. Looking in the api logs, I can see it barely goes over 100ms. I am not sure why I

parallel.foreach and httpclient - strange behaviour

若如初见. 提交于 2020-05-26 03:57:38
问题 I have a piece of code that loops over a collection and calls httpclient for each iteration. The api that the httpclient calls, takes on average 30-40ms to execute. Calling it sequentially, I get the expected outcome, however as soon as I use Parallel.foreach, it takes longer. Looking closely in the logs, I can see quite a few httpclient calls take more 1000ms to execute and then the time drops back to 30-40ms. Looking in the api logs, I can see it barely goes over 100ms. I am not sure why I

Cannot validate token in UseJwtBearerAuthentication. Authorization has been denied

半腔热情 提交于 2020-05-25 07:39:01
问题 Using a single asp.net(4.6.1) web project, apparently I'm unable to validate the jwt token that was generated on the same server. Startup.cs : var secret = Encoding.UTF8.GetBytes("12341234123412341234"); var jwtFormatter = new CustomJwtFormat("Any", "local", secret); // This part checks the tokens app.UseJwtBearerAuthentication(new JwtBearerAuthenticationOptions { AuthenticationType = DefaultAuthenticationTypes.ExternalBearer, AuthenticationMode = AuthenticationMode.Active, // Block requests

Cannot validate token in UseJwtBearerAuthentication. Authorization has been denied

好久不见. 提交于 2020-05-25 07:38:46
问题 Using a single asp.net(4.6.1) web project, apparently I'm unable to validate the jwt token that was generated on the same server. Startup.cs : var secret = Encoding.UTF8.GetBytes("12341234123412341234"); var jwtFormatter = new CustomJwtFormat("Any", "local", secret); // This part checks the tokens app.UseJwtBearerAuthentication(new JwtBearerAuthenticationOptions { AuthenticationType = DefaultAuthenticationTypes.ExternalBearer, AuthenticationMode = AuthenticationMode.Active, // Block requests

Change default type of numeric deserialization

醉酒当歌 提交于 2020-05-23 10:08:31
问题 While I was deserializing some JSON data to DataSet, the resultant dataset may lose its column schema. that means, When I deserialize some JSON, it populates the Dataset with Int64 objects rather than Int32. I would like it to choose Int32. I know, Json.NET by default reads integer values as Int64 because there is no way to know whether the value should be Int32 or Int64. JsonSerializerSettings settings = new JsonSerializerSettings() { Converters = { new PrimitiveJsonConverter() }, }; DataSet

Http route without parameters and a point inside the route

风流意气都作罢 提交于 2020-05-17 07:30:06
问题 I'm currently creating a webservice using ApiController classes. Due to some restrictions I have to put a Point in the route itself (terminal.journalentry). And use this as the base URL. Thus: http://localhost:59684/terminal.journalentry as example for a call. Now though I've run into Problems. When I use the following code with this call: http://localhost:59684/terminal.journalentry it works without a hitch. public class JournalController : ApiController { [HttpGet] [Route("terminal