asp.net-core

EF Core with Cosmos DB provider, UserManager AddLoginAsync gives ConcurrencyFailure

亡梦爱人 提交于 2021-02-15 07:35:24
问题 Creating a new user, fetching the user again with usermanager for testing, and then using the method AddLoginAsync with the recently fetched user gives the error ConcurrencyFailure, Optimistic concurrency failure, object has been modified. When fetching the user the "ConcurrencyStamp" has the correct etag, but after the "AddLoginAsync" I can see the user object has an invalid etag, the ConcurrencyStamp is a GUID. I have followed the documentation and added this to the IdentityUser model

How to set multiple services from Entity Framework Core on Repository Pattern?

孤街浪徒 提交于 2021-02-15 07:34:59
问题 I am trying to build a structure using repository pattern in entity framework core. I have an generic interface and a service for general operations. They simply do CRUD transactions. My interface: public interface IGeneralService<TEntity> where TEntity : class { void Delete(TEntity entityToDelete); void Delete(object id); IEnumerable<TEntity> Get( Expression<Func<TEntity, bool>> filter = null, Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBy = null, string includeProperties = ""

How to set multiple services from Entity Framework Core on Repository Pattern?

半世苍凉 提交于 2021-02-15 07:34:16
问题 I am trying to build a structure using repository pattern in entity framework core. I have an generic interface and a service for general operations. They simply do CRUD transactions. My interface: public interface IGeneralService<TEntity> where TEntity : class { void Delete(TEntity entityToDelete); void Delete(object id); IEnumerable<TEntity> Get( Expression<Func<TEntity, bool>> filter = null, Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBy = null, string includeProperties = ""

Delaying a task in C# - db context disposed

安稳与你 提交于 2021-02-15 04:59:28
问题 I have a situation where I need certain code to execute at a certain time (in my ASP .NET Core project). I know that delaying a task is not a great solution, but this is what I have and I'd like to know how to make it work: async Task MyMethod() { // do something // Create a new thread that waits for the appropriate time TimeSpan time = dbAppointment.ScheduledOn - TimeSpan.FromMinutes(5.0) - DateTime.UtcNow; _ = Task.Delay(time).ContinueWith(async x => await notificationManager.CreateReminder

.Net Core 2 OpenID Connect Authentication and multiple Identities

泪湿孤枕 提交于 2021-02-13 03:51:15
问题 I'm still learning the Identity Framework and am pretty lost in trying to setup authentication in my .Net Core 2 MVC application. Any suggestions are appreciated since I'm not even sure what I'm doing is correct. I have a requirement to integrate an OpenID Connect identity provider for authentication and use a secondary data source for authorization . Inconveniently I cannot use any claim from the OIDC IdP except for the name claim. The rest of the user claims must come from the secondary

.Net Core 2 OpenID Connect Authentication and multiple Identities

 ̄綄美尐妖づ 提交于 2021-02-13 03:50:22
问题 I'm still learning the Identity Framework and am pretty lost in trying to setup authentication in my .Net Core 2 MVC application. Any suggestions are appreciated since I'm not even sure what I'm doing is correct. I have a requirement to integrate an OpenID Connect identity provider for authentication and use a secondary data source for authorization . Inconveniently I cannot use any claim from the OIDC IdP except for the name claim. The rest of the user claims must come from the secondary

.Net Core 2 OpenID Connect Authentication and multiple Identities

喜欢而已 提交于 2021-02-13 03:50:18
问题 I'm still learning the Identity Framework and am pretty lost in trying to setup authentication in my .Net Core 2 MVC application. Any suggestions are appreciated since I'm not even sure what I'm doing is correct. I have a requirement to integrate an OpenID Connect identity provider for authentication and use a secondary data source for authorization . Inconveniently I cannot use any claim from the OIDC IdP except for the name claim. The rest of the user claims must come from the secondary

SignInManager<TUser>.PasswordSignInAsync() is throwing System.Text.Json object cycle exception

人盡茶涼 提交于 2021-02-11 18:16:00
问题 Few days ago I decided to rewrite old API project from .net core 2.0 to 3.1 but today I faced with an error which I cannot solve. After rewriting "AccountManager" class _signInManager.PasswordSignInAsync() starts to throw error connected with Json object cycle. Exception: ((System.Text.Json.JsonException)ex).Message: A possible object cycle was detected which is not supported. This can either be due to a cycle or if the object depth is larger than the maximum allowed depth of 32. Example of

How to implement role authorization with custom database?

試著忘記壹切 提交于 2021-02-11 17:44:49
问题 I have an application which requires role authorization using custom database. The database is set up with a tblUsers table that has a reference to a tblRoles table. The users are also already assigned to their roles. I also want to use the [Authorize(Role = "RoleName")] attribute on each action to check if an authenticated user is assigned to "RoleName" in the database. I'm having a lot of trouble figuring out where I need to make a modification to the [Authorize] attribute so it behaves

How to get AD access token and pass it to web api controller?

孤街醉人 提交于 2021-02-11 17:43:00
问题 How to get AD access token from login.microsoftonline.com and pass access token to web api controller? as I need "access token" as such to pass on to another partner company website url via post request. Below code doing AAD authentication as expected but also I need "access token" as such, public void ConfigureServices(IServiceCollection services) { services.Configure<CookiePolicyOptions>(options => { // This lambda determines whether user consent for non-essential cookies is needed for a