Tag: asp.net identity

使ASP.NET Identity 2.0电子邮件确认令牌适用于WCF和MVC

我有一个服务项目(WCF)和MVC项目,它使用相同的数据库来处理移动和接口部分的服务部分。 我必须在两者上设置电子邮件确认。 我使用OWIN ASP.NET 2.0库进行身份validation,两个项目都有单独的UserManagers。 对于MVC public static ApplicationUserManager Create(IdentityFactoryOptions options, IOwinContext context) { var dataProtectionProvider = options.DataProtectionProvider; if (dataProtectionProvider != null) { manager.UserTokenProvider = new DataProtectorTokenProviderdataProtectionProvider.Create(“ASP.NET”)); } } 对于WCF var provider = new Microsoft.Owin.Security.DataProtection.DpapiDataProtectionProvider(“ASP.NET”); UserManager.UserTokenProvider =new Microsoft.AspNet.Identity.Owin.DataProtectorTokenProvider( provider.Create(“EmailConfirm”)); var code = idManager.UserManager.GenerateEmailConfirmationToken(appuser.Id); 问题在MVC中生成的电子邮件确认令牌工作正常。 在WCF中,当我创建电子邮件确认令牌时,需要从MVC网站进行validation。 在这里,它给了我“无效令牌”。 我认为这是由于令牌代码不匹配,我试图让它们尽可能相同,但我不知道哪一个在Wcf和MVC之间。 顺便说一句。 我在Visual Studio上测试localhost。

如何在ASP.NET IDENTITY中添加自定义表?

我在我的Web表单应用程序上使用ASP.NET标识。 以下是我目前的身份表: 当前身份表 – Role – User – UserClaim – UserLogin – UserRole 我需要添加一个新表来存储其他信息。 新表:UserLogs 新表中的字段: UserLogID(PK) 用户ID(FK) IP地址 LoginDate 如何添加此自定义表? 我知道如何在现有表中添加自定义字段但我不知道如何实现这一点。 感谢您为我的问题找到解决方案的努力。

如何使用Success == true构造IdentityResult

我有一个注入了Microsoft.AspNet.Identity.UserManager的类,我希望userManager.CreateAsync(user,password)方法返回一个IdentityResult.Succeeded = true的Task。 但是,IdentityResult唯一可用的构造函数是失败构造函数,它们将导致Succeeded属性为false。 如何创建具有Succeeded == true的IdentityResult? IdentityResult没有实现接口,而且Succeeded不是虚拟的,所以我没有看到任何通过Rhino Mocks(我用作我的模拟框架)创建模拟对象的明显方法。 我的方法做了类似下面的事情。 提供此示例以说明为什么我可能想要模拟它。 public async Task RegisterUser(NewUser newUser) { ApplicationUser newApplicationUser = new ApplicationUser() { UserName = newUser.UserName, Email = newUser.Email }; IdentityResult identityResult = await applicationUserManager.CreateAsync(newApplicationUser, newUser.Password); if(identityResult.Succeeded) { someOtherDependency.DoSomethingAmazing(); } return identityResult; } 我正在尝试编写unit testing,以确保在identityResult.Succeeded为true时调用someOtherDependency.DoSomethingAmazing()。 谢谢你的帮助!

无法添加和获取自定义声明值

我正在使用带有身份2.0的mvc 5。 我想在应用程序上使用自定义声明值,但我得到null值。 我究竟做错了什么? 更新的代码 帐户控制器中的登录代码 if (!string.IsNullOrEmpty(model.UserName) && !string.IsNullOrEmpty(model.Password)) { AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie); var result = SignInManager.PasswordSignIn(model.UserName, model.Password, model.RememberMe, shouldLockout: false); //Generate verification token Dictionary acceccToken = null; if (SignInStatus.Success == 0) { var userDeatails = FindUser(model.UserName, model.Password).Result; if (userDeatails != null) acceccToken = GetTokenDictionary(model.UserName, model.Password, userDeatails.Id); } if (model.RememberMe) { HttpCookie userid = new HttpCookie(“rembemberTrue”, […]

ASP.NET Core – 自定义AspNetCore.Identity实现不起作用

我正在构建一个完全自定义的AspNetCore.Identity实现,因为我希望TKey全面成为System.Guid 。 尊敬的我,我已经派出类型…… Role : IdentityRole RoleClaim : IdentityRoleClaim User : IdentityUser UserClaim : IdentityUserClaim UserLogin : IdentityUserLogin UserRole : IdentityUserRole UserToken : IdentityUserToken ApplicationDbContext : IdentityDbContext ApplicationRoleManager : RoleManager ApplicationRoleStore : RoleStore ApplicationSignInManager : SignInManager ApplicationUserManager : UserManager **ApplicationUserStore** : UserStore ApplicationUserStore是问题孩子! 履行 namespace NewCo.Identity { using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using System; public sealed class Role […]

为什么在使用带有ASP.Net Identity的ApplicationCookie之前调用SignOut(DefaultAuthenticationTypes.ExternalCookie)?

为什么这个示例在使用ApplicationCookie登录之前调用SignOut for ExternalCookie? 它只是确保身份validation信息干净的一种方法吗? (完整的例子在这里: http : //www.asp.net/identity/overview/getting-started/introduction-to-aspnet-identity ) private async Task SignInAsync(ApplicationUser user, bool isPersistent) { AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie); var identity = await UserManager.CreateIdentityAsync( user, DefaultAuthenticationTypes.ApplicationCookie); AuthenticationManager.SignIn( new AuthenticationProperties() { IsPersistent = isPersistent }, identity); }

ASP.NET Identity 2是否支持匿名用户?

我想允许匿名/尚未注册和注册的用户在我的网站上发布。 Posts (table) – Id (int) – Subject (nvarchar) – Body (nvarchar) – UserId (uniqueidentifier) 该项目使用最新的MS技术(ASP.NET MVC 5 +,C#…)我该怎么做呢? ASP.NET Identity甚至是正确的解决方案吗? 这些之间有什么区别: ASP.NET身份 SimpleMembership 会员提供者 更新我需要能够区分尚未注册的用户并在数据库中记录他们的post。 更新2然后可以选择迁移到已注册的帐户。 就像stackoverflow用于允许匿名用户一样。 这样的东西,但与ASP.NET Identitfy兼容http://msdn.microsoft.com/en-us/library/ewfkf772(v=vs.100).aspx

如何检查用户在asp.net身份中有很多角色

嗨,我需要检查一个用户是否在其中一个角色,我对我找到的不同版本的代码感到困惑。 让我先告诉你我现在的情况 _manager = new UserManager(new UserStore()); var currentUser = _manager.FindById(User.Identity.GetUserId()); if (!_manager.IsInRole(currentUser.Id, “admin”)) { } 和ApplicationUser public class ApplicationUser : IdentityUser { } public class ApplicationDbContext : IdentityDbContext { } 所以我想检查用户是否处于其中一个角色。 例如admin,controbutor,superuser等 我发现这个例子似乎很好但我必须在web.config中进行以下更改才能使其正常工作。 我不需要像我现在那样使用我的代码。 roleManager enabled=”true” 我尝试更多关于UserManager.IsInRole研究,但我找不到很多关于它的内容。 更多阅读我理解我发现的post是关于简单会员。 当我使用Identity时,我不应该使用我找到的代码(指链接和接受的答案),因为这将混合身份和简单成员身份? 特别是我引用这行Roles.GetRolesForUser 。 身份有类似的方法吗? 我认为我对不同的成员资格框架感到困惑,不知道什么是正确的用途。 我希望有人能解释我理解。 (我仍然想要我在标题中提出的问题的解决方案,但我真的需要理解=)

将用户名和姓氏添加到ASP.NET标识2?

我转而使用新的ASP.NET Identity 2.我实际上使用的是Microsoft ASP.NET Identity Samples 2.0.0-beta2。 任何人都可以告诉我在哪里以及如何修改代码,以便它存储用户的名字和姓氏以及用户详细信息。 这现在是否是索赔的一部分,如果是这样,我怎么能添加它? 我假设我需要在这里添加这个帐户控制器中的寄存器方法: if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { var code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); var callbackUrl = Url.Action(“ConfirmEmail”, “Account”, new { userId = user.Id, code = code }, protocol: […]

如何从ASP.NET MVC自定义IdentityUser模型获取用户配置文件数据?

在这篇博客的帮助下,我向ApplicationUser类添加了一个自定义配置文件属性OfficeKey (在IdentityModels.cs文件中): public class ApplicationUser : IdentityUser { public int OfficeKey { get; set; } //remaining code here } 我可以得到这样的用户名: User.Identity.Name 如何获取自定义用户数据OfficeKey ? 我试过这些: 如何从Asp.net mvc模型获取身份用户数据 如何从ASP.NET MVC默认Mempership模型获取用户电子邮件地址? 注意:它是一个带有MySQL成员资格提供程序的ASP.NET MVC 5 Web应用程序。