我尝试通过“个人用户帐户”使用 MVC 5 和 OWIN 创建新项目。问题是当我注册新帐户时,系统要求我输入电子邮件,然后该电子邮件将填充到数据库中的电子邮件和用户名。当我尝试登录时,系统要求我输入电子邮件,但它会将该电子邮件与用户名列进行比较。因此电子邮件和用户名的值是相同的。下面的登录代码正在运行登录(帐户控制器)
var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false);
Run Code Online (Sandbox Code Playgroud)
有没有什么方法可以将输入的电子邮件与电子邮件列而不是用户名进行比较?
有什么方法可以查看ASP.NET Identity 2中生成的密码重置令牌吗?
我的假设是应该有一个字典TokenProvider将这些标记保存在内存中。
更新:
这是一个类似的问题ResetPassword Token 它如何存储以及在哪里存储?
“令牌是使用 SecurityStamp 生成的,并根据 SecurityStamp 进行验证,而不存储在数据库或本地文件存储中的任何位置。”
但问题仍然是框架如何知道令牌何时过期而不存储它?
我了解 .NET Identity,但是有很多关于 Identity 2 和 Identity 3 的文章。后者(Identity 3)似乎只适用于 .NET Core 解决方案。所以正在考虑使用 Identity 2。但我不清楚:
asp.net asp.net-membership asp.net-identity-2 asp.net-identity-3 asp.net-core
我有一个问题我无法理解asp.net身份
应用以下步骤
我的问题是当我通过" WebApplication1 "中的" User1 " 登录时
我发现用User1记录了WebApplication2.
尽管每个项目都有单独的数据库
而且NO用户1在WebApplication2.
有什么问题?
请原谅我糟糕的英语!
asp.net-mvc-5 asp.net-identity asp.net-mvc-5.1 asp.net-identity-2
我已经将默认的MVC5模板修改为使用s / ,而不是使用string/ nvarchar键用户。我的解决方案类似于此处讨论的解决方案:http : //blogs.msdn.com/b/webdev/archive/2013/12/20/announcing-preview-of-microsoft-aspnet-identity-2-0-0- alpha1.aspxGuiduniqueidentifier
我在适用的地方更改了类型参数,但生成的第一个用户的ID为00000000-0000-0000-0000-000000000000。由于第二个用户的主键与第一个用户的主键冲突,因此无法创建。
然后,我将适用的类型参数从更改Guid为int,然后使用从1开始递增的用户ID起作用。
那么我该如何使用它Guid呢?
我必须需要挂接到某个地方,并为每个新创建的用户分配一个新的Guid。最好的地方在哪里?我以为也许在ApplicationUser(实现IdentityUser)构造函数中,但是我不确定。
我试图在最新版本的Visual Studio 2013中扩展Web API 2(带个人帐户)模板中提供的AspNet IdentityRole类.当我点击/ api/roles时,它返回一个空数组
身份模型
namespace API.Models
{
// You can add profile data for the user by adding more properties to your ApplicationUser class, please visit http://go.microsoft.com/fwlink/?LinkID=317594 to learn more.
public class ApplicationUser : IdentityUser<string, IdentityUserLogin, ApplicationUserRole, IdentityUserClaim>, IUser, IUser<string>
{
[NotMapped]
public virtual UserProfile Profile { get; set; }
public virtual ICollection<ApplicationUserRole> UserRoles { get; set; }
//public virtual List<ApplicationUserRole> ApplicationRoles { get; set; }
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager,
string authenticationType)
{
// Note …Run Code Online (Sandbox Code Playgroud) .net entity-framework asp.net-web-api asp.net-identity asp.net-identity-2
我使用带有Identity2.0 AccessFailedCount的Webapi,LockoutEndDateUtc没有在无效的用户名和密码上进行检测.我实现了WebAPI提供的基于令牌的身份验证.请帮忙 .
这是代码片段
using (UserManager<ApplicationUser> userManager = userManagerFactory)
{
ApplicationUser user = await userManager.FindAsync(context.UserName, context.Password);
if (user == null)
{
context.SetError("invalid_grant", "The user name or password is incorrect.");
return;
}
if (await userManager.IsLockedOutAsync(user.Id))
{
context.SetError("lock_out", "The account is locked.");
return;
}
if (!userManager.IsEmailConfirmed(user.Id))
{
context.SetError("inactive_user", "The user is not active. Please check your Register Email to verify.");
return;
}
ClaimsIdentity oAuthIdentity = await userManager.CreateIdentityAsync(user,
context.Options.AuthenticationType);
ClaimsIdentity cookiesIdentity = await userManager.CreateIdentityAsync(user,
CookieAuthenticationDefaults.AuthenticationType);
AuthenticationProperties properties = CreateProperties(user);
AuthenticationTicket ticket = new …Run Code Online (Sandbox Code Playgroud) asp.net asp.net-mvc asp.net-web-api asp.net-web-api2 asp.net-identity-2
请参阅此类似问题:需要在User.Identity中访问更多用户属性
我想创建自定义身份验证方法以与我的Razor视图一起使用,它允许轻松访问IdentityUser与User.Identity对象关系的属性,但我不确定如何去做.我想创建一个类似于几个自定义扩展User.Identity.GetUserName(),User.Identity.GetUserById()等等...而不是使用此ViewContextExtension方法.我的身份验证类型当前是DefaultAuthenticationTypes.ApplicationCookieVS2013 MVC5模板的默认类型.正如Shoe所说,我需要在用户登录后插入此声明.
我的问题是:
如何以及在何处创建具有this IIdentityIPrincipal下的out参数的自定义声明?
这将允许我通过CookieAuthentication在DDD设置中的实体的View中访问用户属性,其中我在使用Identity 2.0的单个应用程序中有多个DbContexts.我最终将使用WebAPI,但是现在我希望尽可能简单.我找到了这个SO Q&A但是它适用于使用Tickets的Web Forms.不确定门票和代币之间的区别吗?
这是ViewContext从基本控制器使用的当前方法:
视图:
@using Microsoft.AspNet.Identity
@using Globals.Helpers
@using Identity //custom Identity for Domain
@using Microsoft.AspNet.Identity.Owin
@if (Request.IsAuthenticated)
{
var url = @ViewContext.BaseController().GetAvatarUrlById(User.Identity.GetUserId<int>());
//...
}
Run Code Online (Sandbox Code Playgroud)
BaseController.cs
public string GetAvatarUrlById(int id)
{
var user = UserManager.FindById(id);
return "../../" + user.ImageUrl;
}
Run Code Online (Sandbox Code Playgroud)
Extensions.cs
public static class ViewContextExtension
{
public static BaseController BaseController(this ViewContext view)
{
var baseController …Run Code Online (Sandbox Code Playgroud) c# class-extensions asp.net-mvc-5 razor-3 asp.net-identity-2
我有一个服务项目(WCF)和MVC项目,它使用相同的数据库来处理移动和接口部分的服务部分.我必须在两者上设置电子邮件确认.
我使用OWIN ASP.NET 2.0库进行身份验证,两个项目都有单独的UserManagers.
对于MVC
public static ApplicationUserManager Create(IdentityFactoryOptions<ApplicationUserManager> options, IOwinContext context)
{
var dataProtectionProvider = options.DataProtectionProvider;
if (dataProtectionProvider != null)
{
manager.UserTokenProvider = new DataProtectorTokenProvider<ApplicationUser>dataProtectionProvider.Create("ASP.NET"));
}
}
Run Code Online (Sandbox Code Playgroud)
对于WCF
var provider = new Microsoft.Owin.Security.DataProtection.DpapiDataProtectionProvider("ASP.NET");
UserManager.UserTokenProvider =new Microsoft.AspNet.Identity.Owin.DataProtectorTokenProvider<ApplicationUser>(
provider.Create("EmailConfirm"));
var code = idManager.UserManager.GenerateEmailConfirmationToken(appuser.Id);
Run Code Online (Sandbox Code Playgroud)
问题 在MVC中生成的电子邮件确认令牌工作正常.
在WCF中,当我创建电子邮件确认令牌时,需要从MVC网站进行验证.在这里,它给了我"无效令牌".
我认为这是由于令牌代码不匹配,我试图让它们尽可能相同,但我不知道哪一个在Wcf和MVC之间.
顺便说一句.我在Visual Studio上测试localhost.
我有一个使用ASP.net身份2.0进行用户管理的网站,还有一些外部身份验证选项(google,facebook等).
我想让用户选择删除他们的帐户.我在这个答案中找到了一个很好的例子:ASP.NET MVC 5如何在Identity 2.0中删除用户及其相关数据
但是,我希望限制其他人在删除其帐户时注册旧用户的用户名.但是,如果他们决定重新注册,则应释放该电子邮件.
我想阻止用户ABC删除他们的帐户,然后有人无关使用用户名ABC(这会导致我的用例混乱/问题).
我正在寻找有关如何实现这一点的最佳实践的建议.ASP身份中是否有任何内置?或者我应该在所有已注册用户名(已删除和活动)的某处保留list/sql db,并只是根据此列表检查新用户?
谢谢.