asp.net-identity

ASP.NET HttpContext is null in 4.6.1 sample project

自古美人都是妖i 提交于 2019-12-12 09:57:07
问题 1) Create new MVC app targeting 4.6.1 (not core, using MSVS 2015 Update 3) 2) In the generated class ApplicationUser.cs add an assertion: public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager) { HttpContext httpContext = HttpContext.Current; Debug.Assert(httpContext != null); // assertion fails // ... } 3) Run program in the debugger, login, the assertion fires. This workaround fixes the problem however I was told that HttpContext should be available

How to retrieve Users with a specific role via Linq in ASPnet Identity

谁说胖子不能爱 提交于 2019-12-12 09:49:31
问题 I need to retrieve all users of a specific role, something I think should be made straightforward, however, here is the problem. The Roles navigation Property of ApplicationUser is not the list of roles (IdentityRole) but a collection of (IdentityUserroles) the intermediate table that links users and roles. So, this is the code I have, but it does not work. [HttpPost] [Authorize(Roles = "Admin, Recepcionista, Orientador")] public ActionResult SearchResults(SearchCriteriaViewModel criteria) {

HttpContext.Current is null inside Identity Framework's methods

丶灬走出姿态 提交于 2019-12-12 09:37:01
问题 I am using ASP.NET MVC 5 and Identity Framework. When I call UserManager.UpdateAsync(...) my eventhandlers on ApplicationDbContext() SaveChanges will run. Here I am using HttpContext.Current for different purposes (logging and auditing) so I must get say current user. However the whole method runs in a worker thread, and here HttpContext.Current is null. The biggest problem that the UserManager's "sync" methods are only wrappers around the async version, so the calls are serialized, but the

Why this violates the constraint of type parameter 'TUser'?

南笙酒味 提交于 2019-12-12 08:47:52
问题 I am trying to customize asp.net identity entities with the following ones: public class User : IdentityUser<string, UserClaim, UserRole, UserLogin> public class UserClaim : IdentityUserClaim<string> public class UserLogin : IdentityUserLogin<string> public class UserRole : IdentityUserRole<string> public class UserToken : IdentityUserToken<string> public class Role : IdentityRole<string, UserRole, RoleClaim> public class RoleClaim : IdentityRoleClaim<string> I have then created a DbContext

Asp .Net Identity 2 - Logging out other sessions (using security stamp) after password update also logs out current session

纵饮孤独 提交于 2019-12-12 08:04:51
问题 I need to immediately invalidate and log out any other logged in sessions when a user changes their password, but allow the active session (who has just updated their password) to remain logged in. To do this, I'm using the UpdateSecurityStampAsync(currentUser.Id); method on the UserManager. All other sessions are successfully logged out, but the active session is also logged out despite the call to SignInAsync after updating the security stamp. The Identity configuration I'm using is as

Integrate facebooksdk with Identity 2.0

我只是一个虾纸丫 提交于 2019-12-12 06:15:28
问题 I have an MVC5 app and have figured out how to authenticate with facebook initially using Identity 2.0. Other than adding email to the scope, it is basically default: var options = new FacebookAuthenticationOptions() { AppId = "##################", AppSecret = "######################" }; options.Scope.Add("email"); app.UseFacebookAuthentication(options); In another section of my app, it is possible that the user would need to upgrade the facebook token to be able to publish to their wall as

Customize asp.net identity role claim

﹥>﹥吖頭↗ 提交于 2019-12-12 06:05:52
问题 I'm using asp.net identity with ClaimsPrincipal and ClaimsIdentity. The identity is created by a custom usermanager and sent to the clients as a bearer token. All works fine, but I would like to instruct asp.net to use a custom claim type for role, instead of the standard System.Security.Claims.ClaimTypes.Role (http://schemas.microsoft.com/ws/2008/06/identity/claims/role). Is it possibile? Edit: I would like to use the standard Authorize attribute with role constructor, ex: Authorize(Roles=

MVC 6 - Prevent Cache After Logout

假装没事ソ 提交于 2019-12-12 05:57:14
问题 I'm using MVC 6 and I have implemented Identity 3.0 for authentication. I'm trying to prevent the user from clicking on the browser back button after logout. The closest working solution I came across seems to be not working in MVC 6. Could someone help? [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)] public sealed class NoCacheAttribute : ActionFilterAttribute { public override void OnResultExecuting(ResultExecutingContext filterContext) { filterContext.HttpContext

error when reading asp.net membership tables in MySQL

℡╲_俬逩灬. 提交于 2019-12-12 05:48:40
问题 I have an asp.net website that uses mysql for membership. the web app works well when i am connecting to mysql hosted on windows OS but throws an error due to table name (case-sensitivity) on Linux. The error is not relavant to my tables, but it is related to internal MySQL adapter classes when calling to authenticate a user. Here is the error: Table ' dbname.AspNetUsers' doesn't exist Description: An unhandled exception occurred during the execution of the current web request. Please review

Why Identity 2.0 adds a new column in AspNetUserRoles when I extend IdentityUser?

落爺英雄遲暮 提交于 2019-12-12 04:53:53
问题 I have derived a class from IdentityUser, CustomUser. If I check the database tables, I can see that Identity 2.0 has added a third column to AspNetUserRoles table, called CustomUser_Id. It seems a foreign key to my CustomUser table, but AspNetUserRoles already has UserId column, so it seems redundant. Why? What I am missing? 回答1: I'm assuming you've also got ApplicationUser hanging around. IdentityUser is an abstract class, so the column in dbo.AspNetUserRoles is attached to whatever