asp.net-core-webapi

What is the best practice in EF Core for using parallel async calls with an Injected DbContext?

╄→гoц情女王★ 提交于 2019-12-03 01:31:45
I have a .NET Core 1.1 API with EF Core 1.1 and using Microsoft's vanilla setup of using Dependency Injection to provide the DbContext to my services. (Reference: https://docs.microsoft.com/en-us/aspnet/core/data/ef-mvc/intro#register-the-context-with-dependency-injection ) Now, I am looking into parallelizing database reads as an optimization using WhenAll So instead of: var result1 = await _dbContext.TableModel1.FirstOrDefaultAsync(x => x.SomeId == AnId); var result2 = await _dbContext.TableModel2.FirstOrDefaultAsync(x => x.SomeOtherProp == AProp); I use: var repositoryTask1 = _dbContext

Multiple connection to DbContext in EFCore and .net Core2.0

只谈情不闲聊 提交于 2019-12-03 00:51:46
问题 I have facing a problem to connecting to DBcontext with multiple connection. please help me out from this problem , here is me scenario . I have an Angular5 application and Webapi Controllers. I have 4 databases and Each database has different users . When 4 user are trying to connecting to their database at Same time through Webapi controller , that time all users are getting data from single database (instead of getting different database ) . When we try to Connecting one by one then data

No Individual User Accounts auth option in ASP.NET Core Web API template

荒凉一梦 提交于 2019-12-02 23:39:12
I am a bit confused as to why there is no Individual User Accounts authentication option in the latest ASP.NET Core Web API template. Is it still possible to implement individual user accounts the way that the MVC template does or would it not make sense? Let's say I am creating a stand-alone web API that is going to have all of my business logic and data layer that accesses the database which has the AspNet Identity tables. I plan on making calls to this API w/ an MVC app. I know one way of doing this is to create an asp.net MVC app w/ individual user accounts auth and simply build the API

ASP.net core web api: Using Facebook/Google OAuth access token for authentication

大城市里の小女人 提交于 2019-12-02 20:40:47
For serveral days now I am trying to get OAuth authentication with Google and Facebook to work within my ASP.net core web api project. my current status is: I have an ASP.net core Web Api project in which the users need to be authenticated I have an angular 2 web app which should use my web api (with authentication) I have an android app, which should use my web api (with authentication) my goal is: Using Google/Facebook as OAuth providers for login later: adding own user accounts (probably with IdentityServer4) no need to redirect to a special login website (like the IdentityServer4 solution)

How do I get current user in .NET Core Web API (from JWT Token)

試著忘記壹切 提交于 2019-12-02 20:16:51
After a lot of struggling (and a lot of tuturials, guides, etc) I managed to setup a small .NET Core REST Web API with an Auth Controller issuing JWT tokens when stored username and password are valid. The token stores the user id as sub claim. I also managed to setup the Web API to validate those tokens when a method uses the Authorize annotation. app.UseJwtBearerAuthentication(...) Now my question: How do I read the user id (stored in the subject claim) in my controllers (in a Web API)? It is basically this question ( How do I get current user in ASP .NET Core ) but I need an answer for a

Empty authorization header on requests for Swashbuckle.AspNetCore

女生的网名这么多〃 提交于 2019-12-02 13:29:13
Currently having an issue with authorization headers in swashbuckle for .net core The first line of code on every endpoint is: string auth = Request.Headers["Authorization"]; When using postman, everything works smoothly, but when making a request from localhost/swagger, the header is empty when a breakpoint is inserted, the header is a null value. the body of the request is in tact and everything works properly when the authorization is removed from the endpoint In my services.AddSwaggerGen I add the security definition: services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Info { Version =

Multiple connection to DbContext in EFCore and .net Core2.0

杀马特。学长 韩版系。学妹 提交于 2019-12-02 13:25:53
I have facing a problem to connecting to DBcontext with multiple connection. please help me out from this problem , here is me scenario . I have an Angular5 application and Webapi Controllers. I have 4 databases and Each database has different users . When 4 user are trying to connecting to their database at Same time through Webapi controller , that time all users are getting data from single database (instead of getting different database ) . When we try to Connecting one by one then data getting correctly . Here is my sample code for dynamic connection . Context Connectionstring : protected

where can be stored user info in .net core API project with angular

帅比萌擦擦* 提交于 2019-12-02 12:38:24
I have an angular project and i am using .net core 2.o Web API. I stored my user info in Jwt and i want log every database operation. I can access user info by sending jwt and taking from request.header in server side. But the problem is, where can be stored? In my old mvc projects, i could stored in session. But this project is API . And we work with JWT not session. How can i achieve that store UserInfo during the request start to end. And i want to access UserInfo from everywhere. This is my actionFilter: public class TestFilterAttribute : System.Web.Http.Filters.FilterAttribute,

Redirect to action after finishing background task queue

倖福魔咒の 提交于 2019-12-02 11:20:27
I'm working on a .Net core solution that takes backup of storage files from another microservice and because this process takes too long time, we decided to build this routine under a background task.By following this link: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/host/hosted-services?view=aspnetcore-2.1 I have implemented the background by using Queued background tasks like the following : public interface IBackgroundTaskQueue { void QueueBackgroundWorkItem(Func<CancellationToken, Task> workItem); Task<Func<CancellationToken, Task>> DequeueAsync( CancellationToken

Asp.net core 2.2 ModelBinder Unit Test Issues

岁酱吖の 提交于 2019-12-02 08:19:21
问题 I'm seeing odd behavior while attempting to debug xUnits against components of the asp.net core pipeline. The code posted below has all purposeful functionality stripped out to illustrate the problem only which is : Not hitting all my breakpoints in JsonModelBinder. Not exiting on "return Task.Completed" even though it's being evaluated. The production code for JsonModelBinder contains more logic to deserialize the incoming string data. This code contains failure logic which contains a number