asp.net-identity-2

Allow only a single login session per user

蹲街弑〆低调 提交于 2019-12-11 13:01:51
问题 Essentially I am asking this question here, but I am using ASP Identity instead of the ASP.Net Membership provider, and with that, that answer is of no use to me. 回答1: Figured out how to do it. On login I call this: var key = user.UserName; var timeOut = new TimeSpan(0, 0, HttpContext.Current.Session.Timeout, 0, 0); HttpContext.Current.Cache.Insert(key, Session.SessionID, null, DateTime.MaxValue, timeOut, CacheItemPriority.NotRemovable, null); And this in the Global.asax if (Session["username

Change seed method for an existing Asp.Net MVC 5 (Identity 2) application?

两盒软妹~` 提交于 2019-12-11 12:02:13
问题 How to add a fixed role (e.g. Admin) to an existing Asp.Net Mvc/Identity 2 site? In the link http://bitoftech.net/2015/03/11/asp-net-identity-2-1-roles-based-authorization-authentication-asp-net-web-api/, there are the following code which is exactly what I want to do. However, will the Seed function be executed since the application? (I already have some code, var lookup1 = new List<L1>{new L1 {...},...}; tableL1.ForEach(l => context.tableL1.AddOrUpdate(p=>p.Title, l)); context.SaveChanges()

ASP.NET Identity Change ExpireTimeSpan after ConfigureAuth

元气小坏坏 提交于 2019-12-11 11:50:03
问题 I'm working on a web application that I recently migrated from a custom authentication solution to ASP.NET Identity. In some sections of our app, long processes are performed that can take up to an hour to run. Under normal circumstances, we want users to be automatically logged out after 30 minutes of non-activity. However, for screens where long processes occur, we want to widen the automatic logout window so that they don't get kicked out before the process completes. I'm currently

Adding Identity 2.0 Roles to custom Identity

馋奶兔 提交于 2019-12-11 11:19:02
问题 I recently started work on a new application using MVC 5 and Identity 2.0, in order to use a different password hashing algorithm I implemented the custom identity detailed in this guide (https://code.msdn.microsoft.com/ASPNET-45-MVC5-Custom-1a94ab26#content). I have looked at various ways of incorporating roles into this identity implementation but so far have not found a way of making them work with this new identity implementation. Does anyone now of a guide on how to go about adding roles

How can keep the user logged in even after the browser has closed with Identity ASP.NET MVC framework?

回眸只為那壹抹淺笑 提交于 2019-12-11 07:05:58
问题 Currently, each time the user browser closes, he/she will have to login again. When they login, this is the code that I use to sign them in Identity. SignInManager.SignIn(user, false, false); Here is how my Authentication is configured today public void ConfigureAuth(IAppBuilder app) { app.CreatePerOwinContext(ApplicationDbContext.Create); app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create); app.CreatePerOwinContext<ApplicationSignInManager>

ASP.NET Identity - setting UserValidator does nothing

不想你离开。 提交于 2019-12-11 06:56:58
问题 I'm trying to set the UserValidator for the default ApplicationUserManager in a new ASP.NET MVC 5 project (using ASP.NET Identity 2). I've created a very simple UserValidator: public class SimpleUserValidator<TUser, TKey> : IIdentityValidator<TUser> where TUser: class, IUser<TKey> where TKey : IEquatable<TKey> { private readonly UserManager<TUser, TKey> _manager; public SimpleUserValidator(UserManager<TUser, TKey> manager) { _manager = manager; } public async Task<IdentityResult>

How to get Role.Name in Razor View?

不羁的心 提交于 2019-12-11 06:29:01
问题 I am using @model IEnumerable<WebApplication.Models.ApplicationUser> View @foreach (var user in Model) { <tr> <td> @foreach(var role in user.Roles){ role.Name; //invalid role.RoleId; //valid role.UserId; //valid } </td> </tr> } Model public class ApplicationUser : IdentityUser { [Required] public string FirstName { get; set; } [Required] public string LastName { get; set; } public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager) { // Note the

Add Columns/Properties to AspNetUserLogins/Logins in IdentityDbContext

孤街醉人 提交于 2019-12-11 01:59:07
问题 Is it possible to add columns to the AspNetUserLogins table, or subclass the IdentityUserLogin class, such that the Identity Framework will use that class properly? 回答1: This is an answer but I'm sure it's not going to end up the best one: It can be done, but it's ugly. First, you'll want to make a class of all the generics you're about to use, just to make your life easier. Those are: [Table("AspNetUserRoles")] public class StandardUserRole : IdentityUserRole<string> [Table("AspNetRoles")]

Multiple cookies issue in OWIN security AuthenticationHandler

老子叫甜甜 提交于 2019-12-10 21:05:28
问题 I am using Facebook Owin Authentication and more or less follow Microsoft sample. I am more or less following the First time user logs in, everything is ok. But if they sign out and try again, it seems like the previous .AspNet.Correlation.Facebook is not removed, but set to empty string. So my next call to api/getexternallogin looks like this in Fiddler: This is when we are generating a correlationId and having multiple cookies at this point is not a show stopper. In the response, I set it

Writing a custom IUserPasswordStore and SignInManager.PasswordSignInAsync in Identity 2.1

冷暖自知 提交于 2019-12-10 13:16:24
问题 Building a custom IUserPasswordStore to connect to a legacy system's username/password table. The password is hashed with custom code in the table so I need to write custom code for PasswordSignInAsync . Do I need to override PasswordSignInAsync or is there a method I can provide that just does the hashing of the password? If I do override the entire PasswordSignInAsync is there sample code somewhere showing me what needs to be done in the method? 回答1: That was easier than I thought. Override