asp.net-identity

ASP.Net Identity built in functions with custom tables in ASP.Net Core

北城以北 提交于 2019-12-02 00:16:22
I am using ASP.Net Core Web Api 2 on .Net 2.1 Framework I have custom AppUsers and AppRoles tables, linked with bridge table AppUserRoles My main problem is that I want to use [Authorize(Roles = "UserRole")] As User.Identity is working fine and I am getting user Id from User.Identity.Name I thought there was some way to set roles and check them before controller request, or to use User.IsInRole("UserRole") for checking inside controller. Is it possible to rebuild or overload .IsInRole("UserRole") function or [Authorize(Roles = "UserRole")] attribute background function somehow, so I could

Why does a role shows as “not exist” even when present in the database (asp.net mvc)

夙愿已清 提交于 2019-12-01 22:59:45
I'm trying to add users to a role when registering a user so i seeded the roles and updated the database with the code below in the migrations.cs class var RoleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(context)); string[] roleNames = { "Admin", "Reviewer", "User" }; IdentityResult roleResult; foreach (var roleName in roleNames) { if (!RoleManager.RoleExists(roleName)) { roleResult = RoleManager.Create(new IdentityRole(roleName)); } } i tried to fetch the roleNames into a dropdownlist in my accountcontroller class public ActionResult Register() { var model = new

Interfaces for mocking ConfirmEmailAsync and other UserManager methods in MVC5

早过忘川 提交于 2019-12-01 22:33:45
问题 I am trying to unit test this controller method, which comes out of the box in current MVC projects. [AllowAnonymous] public async Task<ActionResult> ConfirmEmail(string userId, string code) { if (userId == null || code == null) { return View("Error"); } var result = await UserManager.ConfirmEmailAsync(userId, code); return View(result.Succeeded ? "ConfirmEmail" : "Error"); } The AccountController has a constructor which will take an ApplicationUserManager and a ApplicationSignInManager as

What is CreatePerOwinContext replacement in AspNetCore?

こ雲淡風輕ζ 提交于 2019-12-01 22:03:09
问题 What is the CreatePerOwinContext replacement, if any, in AspNetCore? I'm trying to migrate the Asp.Net Identity samples to AspNet Core, and finding that the legacy? package that provides the CreatePerOwinContext extension method is not compatible with Asp.Net Core framework. 回答1: After some digging...it seems that CreatePerOwinContext was primarily part of a dependency injection mechanism. Microsoft.AspNetCore 1.0.0 supports dependency injection as a first-class citizen. https://docs.asp.net

Interfaces for mocking ConfirmEmailAsync and other UserManager methods in MVC5

穿精又带淫゛_ 提交于 2019-12-01 21:37:09
I am trying to unit test this controller method, which comes out of the box in current MVC projects. [AllowAnonymous] public async Task<ActionResult> ConfirmEmail(string userId, string code) { if (userId == null || code == null) { return View("Error"); } var result = await UserManager.ConfirmEmailAsync(userId, code); return View(result.Succeeded ? "ConfirmEmail" : "Error"); } The AccountController has a constructor which will take an ApplicationUserManager and a ApplicationSignInManager as parameters, and the matching properties with private setters to use for testing. However, I can't figure

Session logged out too soon

蹲街弑〆低调 提交于 2019-12-01 21:28:47
I'm using ASP.NET Core 2.1 with Microsoft Identity and users are complaining that they keep getting redirected to the login screen after only around 30 minutes of inactivity. I've set it up with 60 minutes in the ExpireTimeSpan, but it's never lasting anywhere near that long. Any suggestions? This is what I have in the Startup.cs file: public void ConfigureServices(IServiceCollection services) { services.AddScoped<IRFDbRepository, RFDbRepository>(); var connection = _configuration.GetConnectionString("RFDbConnection"); services.Configure<ConnectionStrings>(_configuration.GetSection(

How to use DI with UserManager and UserStore

不打扰是莪最后的温柔 提交于 2019-12-01 20:32:11
问题 Given a typical setup of a MVC controller constructor passing UserManager (which takes UserStore ) to it's parent class, how would this be converted to be injected via IoC? Starting with this: public AccountController() : this(new UserManager<ApplicationUser>( new UserStore<ApplicationUser>(new ApplicationDbContext()))) { } I would think something like this: public AccountController(IUserStore store) : this(new UserManager<ApplicationUser>(store))) { } Though this does, of course, lose the

Fully utilizing MVC Owin identity with n(3)-tier architecture

别来无恙 提交于 2019-12-01 20:24:16
问题 I've been learning out of the box Owin Identity and I love the ease of use it provides us with user management. Then problem that I have is that it interacts directly with EF (seemingly) via ApplicationDbContext which I don't want. I would prefer to utilize my 3 tier architecture, IE it interacts with a service layer (BLL) which interacts with EF. I can't find a template, tutorial, or even starting point to maintain all the functionality that is provided and achieve the separation I want. So

Customised IdentityUserRole primary key

让人想犯罪 __ 提交于 2019-12-01 19:59:44
问题 I'm using ASP.NET Identity Provider and EF 6 Code First and I have created a custom IdentityUserRole table which has an extra column OrganisationId . The custom table is named UserRole. The table currently has the default primary key of UserId and RoleId . I would like to have the OrganisationId column included in the Primary Key of the IdentityUserRole table. I can see the UserRole table in my database, and it's the one that's being used for the userroles (there's no aspnet_userrole table

Fully utilizing MVC Owin identity with n(3)-tier architecture

∥☆過路亽.° 提交于 2019-12-01 19:10:45
I've been learning out of the box Owin Identity and I love the ease of use it provides us with user management. Then problem that I have is that it interacts directly with EF (seemingly) via ApplicationDbContext which I don't want. I would prefer to utilize my 3 tier architecture, IE it interacts with a service layer (BLL) which interacts with EF. I can't find a template, tutorial, or even starting point to maintain all the functionality that is provided and achieve the separation I want. So is there a way to use a service layer in place of the ApplicationDbContext in MVC Identity package. If