asp.net-identity-2

How Can I get UserId from ConnectionId in asp.net identity framework SignalR?

雨燕双飞 提交于 2019-12-24 17:43:30
问题 I am using Asp.net Identity framework for authentication. Now I need the User id of connected client from connectionId or role of connected user. 回答1: public class WhateverHub : Hub { public override Task OnConnected() { //Get the username string name = Context.User.Identity.Name; //Get the UserId var claimsIdentity = Context.User.Identity as ClaimsIdentity; if (claimsIdentity != null) { // the principal identity is a claims identity. // now we need to find the NameIdentifier claim var

Where to filter Identity 2.0 claim ticket in a WebAPI app?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-24 15:42:44
问题 ASP.NET apps using OWIN permit multiple Identity sources (Facebook, Google, etc.). Most of the provider-specifc information those sources provide is irrelevant to my app, potentially even large, and I don't want it in my cookies all session. My app is primarily WebAPI, but I suspect the question applies equally to MVC and WebForms. For now, all I need is an integer account ID. Where/when should I reconstruct the identity, after external authentication? For example, here is one way I could

Does submit button passes its value to action method, on form submit?

旧巷老猫 提交于 2019-12-24 10:38:10
问题 Update: What are the control/fields whose value would be submitted when the form is post back? In an ASP.NET MVC Form, if user double clicks on the submit button, the form would be submitted two times. In order to solve this problem I implemented the solution explained here. This is my solution, where I disable the submit button on form submit so it cannot be clicked again: function preventFromBeingDoubleSubmitted() { $('form').each(function () { $(this).submit(function (e) { if ($("form")

find user role in identity asp mvc

北城以北 提交于 2019-12-24 06:35:25
问题 I am using this code for login. How can I find a user role when user login? [HttpPost] [AllowAnonymous] [ValidateAntiForgeryToken] public async Task<ActionResult> Login(LoginViewModel model, string returnUrl) { if (!ModelState.IsValid) { return View(model); } var user = await UserManager.FindByNameAsync(model.Username); if (user != null) { if (!await UserManager.IsEmailConfirmedAsync(user.Id)) { ViewBag.errorMessage = "You must have a confirmed email to log on."; return View("Error"); } } var

Extra column/field on IdentityUserRoles table using Identity 2 and Entity Framework 6

柔情痞子 提交于 2019-12-24 03:08:59
问题 I'm using a custom implementation of the IdentityUser class in my project. The problem is that Entity Framework adds an extra column in the table IdentityUserRoles , mapping the child class Id as a constraint. I know that EF is probably getting confused on figuring how to map the relationship with this new class, I just don't know why and how to solve it. I've been searching the web about this EF behavior, but couldn't find a solution yet. Here are some screenshots that summarize the problem:

Using HttpContext in controller constructor

眉间皱痕 提交于 2019-12-24 00:44:31
问题 I was trying to set a property in the constructor af a controller like this: public ApplicationUserManager UserManager { get; private set; } public AccountController() { UserManager = HttpContext.GetOwinContext().Get<ApplicationUserManager>(""); } But as explained here: https://stackoverflow.com/a/3432733/1204249 The HttpContext is not available in the constructor. So how can I set the property so that I can access it in every Actions of the Controller? 回答1: You can move the code into a read

MVC Identity 2.2.1 - Primary Key (Guid) as UniqueIdentifier instead of nVarChar(128)

馋奶兔 提交于 2019-12-24 00:42:54
问题 Current project: ASP.NET 4.5.2 MVC 5 Identity 2.2.1 One of the problems I am running into is that I am making use of GUIDs properly throughout the rest of the project, with the DB field types being UniqueIdentifier. Unfortunately, Identity does not play by the same rules, and for some inscrutable reason they created the table fields as a string -- nVarChar(128). I have found a few hits out there that show how to properly modify Identity to use UniqueIdentifier and cast the Guids to the proper

PasswordSignInAsync working locally but not in Azure

老子叫甜甜 提交于 2019-12-23 23:22:20
问题 I have a web app running .Net 4.5.1 and Identity 2. In my WebApi I have an iOSLoginController.cs using code grafted from the main .NET Identity's AccountController.cs. It's being fed from my iOS app using AFNetworking 2.0. It works fine locally in my local iis. Logs in fine. But when published to Azure, it isn't actually logging in but it still says 'success' at: var result = await SignInManager.PasswordSignInAsync(usernameToCheck, model.Password, false, shouldLockout: false); // switch on

User gets logged out with 'Remember me'

怎甘沉沦 提交于 2019-12-23 18:53:34
问题 I seem to have some trouble understanding the way Identity 2.0 and cookies work. ASP.NET MVC 5. What I want: If a user logs in and he checks the checkbox 'Remember me', I don't want him to be logged out ever.. But what happens is: the user gets logged out after a certain timespan. The 'Remember me' functionality works if the user closes the browser before the timespan. (When he reopens the website, he's still logged in.) This is the code I have for signing in: public async Task<ActionResult>

ASP.NET Identity verify if ResetPassword token has expired

别等时光非礼了梦想. 提交于 2019-12-23 11:52:58
问题 In my API I have 2 endpoints, first that generates email to reset password form (I generate token using UserManager.GeneratePasswordResetTokenAsync ). Second endpoint is for actual password reset (I use UserManager.ResetPasswordAsync ). My requirement was to verify if token that is required for password reset isn't expired. Searching over GitHub I found this issue and from what I found this isn't possible by design. However searching deeper I've found that UserManager.ResetPasswordAsync