Tag: asp.net identity

dependency injectionUserManager正在处理异步调用(ASP.NET CORE)

我正在使用ASP.NET Core及其内置的dependency injection和asp.net身份。 我遇到的问题是每当我尝试通过异步访问任何上下文时(即在此示例中为UserManager ),它在访问时都会被处理掉。 例如,我的控制器在下面(我们关注的对象是UserManager ) private readonly ApplicationDbContext _dbContext; private readonly UserManager _userManager; private readonly ViewRender _view; private readonly IConfiguration _config; public UserController(ApplicationDbContext dbContext, UserManager userManager, ViewRender view, IConfiguration config) { this._dbContext = dbContext; this._userManager = userManager; this._view = view; this._config = config; } 请注意,正在使用startup.cs中的visual studio模板默认设置注入_userManager 现在在这个控制器的方法中我尝试以下方法: [HttpDelete] public async void Delete(string id) […]

AspNet核心身份,如何设置options.Cookie.SameSite?

在最新的模板和库中使用了httpsonly标志。 我怎么能把它关掉? 同样的问题已经过时,它没有完整的配置示例: AspNet核心身份 – cookie未在生产中设置

ASP.NET身份确认电子邮件是纯文本而不是HTML

在ASP.NET MVC5 C#应用程序中,我使用标准代码在用户注册时发送确认电子邮件,这是我在多个项目中完成的事情: var callbackUrl = Url.Action(“ConfirmEmail”, “Account”, new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); await UserManager.SendEmailAsync(user.Id, “Confirm your account”, “Please confirm your account by clicking here”); 通常,当收件人收到电子邮件时,其内容类型为text / html。 但是,在这一个应用程序中,电子邮件以内容类型text / plain到达,内容不呈现为html,它呈现为纯文本。 它应该是这样的: 请点击此处确认您的帐户 但它看起来像这样: Please confirm your account by clicking here 我搜索了文档,但找不到任何表明为什么会这样或者确实如何改变这种行为的信息。 我还更新了最新版本的Microsoft ASP.NET身份核心(2.2.1),这可能有所帮助,但它对此问题没有任何影响。 我还测试了从Google Apps电子邮件帐户发送的另一个组织(我使用其他具有相同代码的应用程序发送此确认电子邮件并知道它以html格式发送),以防有重要的设置。 关于它为什么以text / plain发送的任何想法以及我如何解决这个问题? […]

在用Identity注册时为用户设置角色的正确方法

我有一个问题,我是新手,但我仍然想知道在注册时为用户分配角色的正确方法是什么? 我这里有一个代码: [HttpPost] [AllowAnonymous] [ValidateAntiForgeryToken] public async Task Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser() { UserName = model.UserName }; RoleManager = new RoleManager(new RoleStore(new ApplicationDbContext())); IdentityRole role = new IdentityRole(“Admin”); await RoleManager.CreateAsync(role); // Store Gender as Claim user.Claims.Add(new IdentityUserClaim() { ClaimType = ClaimTypes.Gender, ClaimValue = “Male” }); //user.Roles.Add(new IdentityUserRole() { […]

高效缓存身份相关实体

我正在使用asp.net MVC5和asp.net Identity v2(来自每晚版本),但我认为这个问题仍然适用于Identity V1。 我有一个会员系统,我通过membershipuser表中的字段AspUserId将AspNetUser实体链接到我的membershipuser实体。 public partial class membershipuser { public int id { get; set; } public string full_name { get; set; } public string address { get; set; } public string AspNetUserId { get; set; } ….. } 我想知道在请求的生命周期中缓存您的成员资格用户记录的最佳方法是什么。 这条路: public static class extensions { public static membershipuser GetMember(this System.Security.Principal.IPrincipal User) { […]

使用带有Asp.net Identity 1.1 Alpha的Guid和自定义表名创建自定义实现

我正在从不同的问题中提取(下面列出我提出的问题)。 我想做五件事,据我所知,这些问题和答案……所有这一切都可以在我的OnModelCreating方法中完成。 前言 :我正在使用Asp.Net Identity 1.1-alpha的最新夜间位 我想在AspNetUsers表中使用“UserId”而不是Id作为我的Users Id的属性。 我理解这将涉及在OnModelCreating期间使用“HasColumnName”。 我想使用Guid(uniqueidentifier)作为我的UserId(而不是字符串)的数据类型。 据我所知,这涉及到我自己的POCOS用于IUser类和IUserStore等,因为Hao Kung在这里的答案中表示…… 如何在Microsoft.AspNet.Identity.EntityFramework.IdentityUser中更改id的类型 我想使用我自己的自定义表名,如MyRoles,MyCUserClaims,MyUserLogins,MyUserRoles,MyUsers,如本答案中所示…… 使用Visual Studio 2013 ASP.NET身份时如何更改表名? 所有外键都应该与Asp.net身份表适当地映射,正如郝公在这里所显示的那样…… 使用SQL脚本创建ASP.NET标识表 我想将属性添加到FirstName和LastName的ApplicationUser。 因此,基于以上内容…有人可以向我提供OnModelCreating方法,该方法将相应地创建这些Identity表,其中UserId作为Guid(uniqueidentifier)类型的用户的Id列,在具有自定义名称的表中,具有相应的外键关系,以及FirstName和LastName的ApplicationUser上的两个附加属性?

Asp.net Identity 2.0使用自定义的唯一属性扩展UserValidator

我想在Asp.net Identity 2.0中扩展UserValidator或类似function,不仅要检查唯一的电子邮件,还要检查我选择的唯一值。 我想在下面用Alias做什么的例子。 这是可能的,还是我必须在任何地方写一张支票来更新Alias? public class ApplicationUserManager : UserManager { public ApplicationUserManager(IUserStore store) : base(store) { this.UserValidator = new UserValidator(this) { AllowOnlyAlphanumericUserNames = false, RequireUniqueEmail = true //This does not exist //RequireUniqueAlias = true }; } } public class ApplicationUser : IdentityUser { [Required] public string Alias { get; set; } }

Identity 2.0声明未添加到数据库中

我正在使用MVC5和最新版本的Identity(2.1)我正在尝试为facebook access_token创建用户声明。 我之前从未创建过声明,但据我所知,我的其他身份function正常工作。 我在Startup.Auth.cs中有这行代码: context.Identity.AddClaim(new Claim(“urn:facebook:access_token”, context.AccessToken, xmlSchemaString, “Facebook”)); 如果您需要更多参考,那么完整的代码就在这里: 将facebooksdk与Identity 2.0集成 如果我在该行之后的行中的代码中放置一个中断,我可以看到所有内容都被正确检索,最重要的是content.AccessToken (这是一个巨大的字符串)。 但是,在完成成功登录后,它永远不会进入数据库。 作为测试,我尝试通过将行更改为此来简化它: context.Identity.AddClaim(new System.Security.Claims.Claim(ClaimTypes.Email, “test@example.com”)); 结果相同,没有错误,但没有任何内容添加到数据库中。 然后我尝试在IdentityModels.cs中添加这行代码,它告诉您放置自定义声明: // Add custom user claims here userIdentity.AddClaim(new Claim(ClaimTypes.DateOfBirth, “01/01/1972”)); 相同的结果……没有错误,也从未进入数据库。 任何人都可以想到我的问题可能是什么原因吗? 我的身份设置中唯一自定义的是我关于如何使用用户名而不是电子邮件(作为用户名)的文章。 此外,我在OnModelCreating块中更改了Identity表名称(例如UserClaims),这似乎是一个相当标准的过程。 我有一种感觉,这将是一些新手的举动,但此刻,我很难过。 任何帮助深表感谢。

asp.net身份userName是唯一的吗?

我正在阅读微软的用户身份,并试图在我的MVC5应用程序中应用它们。 据我所知,Id是关键,而userName不是键,定义说它可以为null,所以我问自己……为什么在MVC5项目模板中,当你输入一个已经存在的userName时你会收到错误信息?? 我试图达到userNamevalidation,但我不能。 这是数据库定义: CREATE TABLE [dbo].[AspNetUsers] ( [Id] NVARCHAR (128) NOT NULL, [UserName] NVARCHAR (MAX) NULL, 这是IdentityUser定义,通知(无validation): namespace Microsoft.AspNet.Identity.EntityFramework { public class IdentityUser : IUser { public IdentityUser(); public IdentityUser(string userName); public virtual ICollection Claims { get; } public virtual string Id { get; set; } public virtual ICollection Logins { get; } public […]

如何在asp.net vnext中注册身份validation类型名称

因此,我正在更新MongoDB的开源asp.net身份提供程序,以便与Asp.Net Identity 3.0(又名vnext)一起使用。 到目前为止,我已经能够注册提供程序并创建用户,但是当使用SignInManager时,如果提供了正确的UserName / Pass,我会收到错误 InvalidOperationException:未接受以下身份validation类型:Microsoft.AspNet.Identity.Application 我已经将错误跟踪到这里https://github.com/aspnet/HttpAbstractions/blob/dev/src/Microsoft.AspNet.PipelineCore/DefaultHttpResponse.cs 但我似乎无法看到SignInContext.Accepted名称被添加到SignInContext的位置。 我正在使用VS14 CTP2中使用的所有vnext库的Alpha-2版本 下面是我的Startup.cs public void Configure(IBuilder app) { try { // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940 var configuration = new Configuration(); configuration.AddJsonFile(“config.json”); configuration.AddEnvironmentVariables(); // app.UseLogRequests(“try”); app.UseErrorPage(ErrorPageOptions.ShowAll); app.UseServices(services => { services.AddIdentity() .AddMongoDB(configuration.Get(“Data:MongoIdentity:ConnectionString”), configuration.Get(“Data:MongoIdentity:DBName”)) .AddHttpSignIn(); // Add MVC services to the services […]