asp.net-core-2.1

Using AspNetUserTokens table to store refresh token in ASP.NET Core Web Api

落爺英雄遲暮 提交于 2019-12-04 00:05:21
I'm working with ASP.NET Core Web API application. I'm trying to implement Jwt Token Based Authentication on top of ASP.NET Identity( built in with database tables). I have implemented all scenarios like register user, login etc but now trying to implement refresh token flow( where access token get expired, client need to get replaced access token using refresh token) . I have seen people are creating new table (refreshToken) to store refresh token so it can be validated with access token and new access and refresh tokens will be generated https://www.blinkingcaret.com/2018/05/30/refresh

Access DbContext service from background task

二次信任 提交于 2019-12-03 08:35:33
So ASP.NET Core applications have Dependency Injection built right in. And with Entity Framework Core, you can easily get a scoped DbContext instance from a controller action method. But this is all limited to controller actions. If you need to start a long-running background task from an action that will communicate with the view in the browser by other means like WebSocket, then you suddenly have nothing at all. The background task can't use the action's DbContext because that was scoped and disposed of when the action returns. An easy way would be to use what people call a Service Locator.

VS2017 : Target framework drop down does not show .NET Core 2.1 option

一世执手 提交于 2019-12-03 04:29:53
I have already installed VS2017 Enterprise 15.6.4 . Recently installed .NET Core 2.1.101 SDK from official site I was expecting .NET Core 2.1 as one of the target framework available if I create console or asp.net core application. Can someone help me understanding what I am missing here. As suggested in comments, I installed 15.7 preview 2. Still no luck and same issue. I have faced the same problem. I solved this by installing the right SDKs with Runtime for .NET Core 2.1. Basically to run/create 2.1 projects from VS Preview, you need to install the "2.1.300" (not 2.1.4) .NET Core SDKs and

SignalR with android(Java) having problem

穿精又带淫゛_ 提交于 2019-12-02 12:11:11
问题 I want to make a realtime-communication between android app and a .net core server project.I tried a question in stackoverflow. I followed this one. In android side, I used these libraries implementation files('libs/signalr-client-sdk-android.jar') implementation files('libs/signalr-client-sdk.jar') After that when try to install app,then it shown this message Then I added aar file according to this answer.After that when try to build again another error shown, Failed to resolved:signalr

Inherit from generic class

邮差的信 提交于 2019-12-02 08:25:37
I have .net core 2.1 project. And my repository classes like below. But because of MyDbContext constructor has parameter, I'm getting error like below. When I remove JwtHelper parametrer, it is working perfectly. But, I need adding JwtHelper in MyDbContext.cs for logging auditings. How can I achieve this? 'MyDbContext' must be a non-abstract type with a public parameterless constructor in order to use it as parameter 'TContext' in the generic type or method 'UnitOfWork' UnitOfWork.cs public class UnitOfWork<TContext> : IUnitOfWork<TContext> where TContext : DbContext, new() { protected

SignalR with android(Java) having problem

大憨熊 提交于 2019-12-02 05:57:22
I want to make a realtime-communication between android app and a .net core server project.I tried a question in stackoverflow. I followed this one . In android side, I used these libraries implementation files('libs/signalr-client-sdk-android.jar') implementation files('libs/signalr-client-sdk.jar') After that when try to install app,then it shown this message Then I added aar file according to this answer .After that when try to build again another error shown, Failed to resolved:signalr-client-sdk-android-release After that I added this code into allprojects under repositories flatDir {

Swagger is not generating swagger.json

痴心易碎 提交于 2019-12-02 05:16:38
问题 I have the asp.net core MVC project and separate WebApi project in one solution. I'm adding the swagger following the documentation on github. Here is my Startup.cs of mvc project: public void ConfigureServices(IServiceCollection services) { //... // Adding controllers from WebApi: var controllerAssembly = Assembly.Load(new AssemblyName("WebApi")); services.AddMvc(o => { o.Filters.Add<GlobalExceptionFilter>(); o.Filters.Add<GlobalLoggingFilter>(); }) .AddApplicationPart(controllerAssembly)

How do I unit test model validation in controllers decorated with [ApiController]?

痞子三分冷 提交于 2019-12-02 04:41:31
问题 As pointed out in this anwer to Asp.Net Core 2.1 ApiController does not automatically validate model under unit test, the automatic ModelState validation that ASP.NET Core 2.1's ApiControllerAttribute gives us only works when actualyy requestion the action at runtime, not by calling it with an invalid parameter in a unit test. However, I still want to test if my action actually returns a BadRequestResult when supplying an incorrect model. Is there any way of doing this? I get that I can still

swagger.json paths and definitions are empty. No operations defined in spec

浪子不回头ぞ 提交于 2019-12-02 01:36:56
I am developing a .netcore web application. I am using of swagger and I've made all the necessary adjustments. Unfortunately it does not work and I just see No operations defined in spec! in the swagger output page. The swagger file with /swagger/v1/swagger.json has the following content: { "swagger": "2.0", "info": { "version": "v1", "title": "Something" }, "paths": {}, "definitions": {} } I want to see my controllers and their actions in swagger output page. after some research i was found that my problem was about using swagger along with OData in .NetCore2.1. i found a solution for this

Reference to an ITVF raises a “second operation started on this context before a previous operation completed” exception

爷,独闯天下 提交于 2019-12-02 00:55:09
问题 I am attempting to reference an Inline Table-Valued Function (ITVF) in a Linq query: var results = await ( from v in _context.Vehicles from r in _context.UnitRepairStatus(v.VehicleNumber) <-- ITVF reference orderby v.VehicleNumber select new FooViewModel { ID = v.ID, VehicleNumber = v.VehicleNumber, InRepair = Convert.ToBoolean(r.InRepair) <-- ITFV field } ).ToListAsync(); When the query runs, it generates an error: InvalidOperationException: A second operation started on this context before