Tag: asp.net identity

OpenIdConnectAuthenticationHandler:message.State为null或为空

我正在使用UseOpenIdConnectAuthentication中间件为ASP.Net Core应用程序对Dells云访问管理器令牌提供程序进行身份validation(设置为提供OpenId / OAuth2身份validation)。 以下是代码: app.UseCookieAuthentication(new CookieAuthenticationOptions { AutomaticAuthenticate = true, AutomaticChallenge = true, AuthenticationScheme = “ClientCookie”, CookieName = CookieAuthenticationDefaults.CookiePrefix + “ClientCookie”, ExpireTimeSpan = TimeSpan.FromMinutes(5), LoginPath = new PathString(“/signin”), LogoutPath = new PathString(“/signout”) }); app.UseOpenIdConnectAuthentication(new OpenIdConnectOptions { RequireHttpsMetadata = false, SaveTokens = true, ClientId = “XYZClient_Id”, ClientSecret = “XYZ_ClientSecret”, ResponseType = OpenIdConnectResponseType.Code, PostLogoutRedirectUri = “https://example.com”, […]

ASP.NET 5 MVC6 User.GetUserId()返回错误的id

我在ASP.NET 5中有一个注册用户的简单项目。 我试图通过扩展方法GetUserId()从using System.Security.Claims命名空间获取当前登录用户的id。 不幸的是,这种方法使我不再存在id,我不知道为什么。 这是我的简单代码: var currentUserId = User.GetUserId(); 方法结果: 数据库:

正则表达式默认ASP.NET核心标识密码

注意 :我相信这个问题不是这个问题的重复。 我的问题是处理asp.net核心身份用于密码validation的默认validation规则以及如何制作正则表达式,而链接的问题正在讨论,一般是关于validation密码的行为(这不能解决我的问题) ASP.NET Core启用默认的密码validation 最少8个字符 至少应该有一个号码 至少应该有一个大写字母 至少应该有一个小写字母 应该至少有一个特殊字符(允许哪些特殊字符?) 记住这些条件我尝试制作以下正则表达式,但它不起作用。 ^((?=.*?[AZ])(?=.*?[az])(?=.*?[0-9])|(?=.*?[AZ])(?=.*?[az])(?=.*?[^a-zA-Z0-9])|(?=.*?[AZ])(?=.*?[0-9])(?=.*?[^a-zA-Z0-9])|(?=.*?[az])(?=.*?[0-9])(?=.*?[^a-zA-Z0-9])).{8,}$ 即使当点2,3,4,5中的三个条件中的任何一个匹配时,该正则表达式也接受字符串。 但我希望所有条件都应该满足。 我在这做错了什么?

User.Identity.GetUserId是否已缓存或每次从数据库中获取?

我正在使用ASP.Net MVC 5,我在我的代码中调用了这一行 string userId = User.Identity.GetUserId(); ASP.NET MVC是否会从表中为每次调用获取此内容,还是会缓存?

如何向User.Identity添加另一个Propertys来自身份2.2.1中的表AspNetUsers

我首先在asp.net身份2.2.1(AspNetUsers表)代码中添加一些新属性 public class ApplicationUser : IdentityUser { public string AccessToken { get; set; } public string FullName { get; set; } public string ProfilePicture { get; set; } public async Task GenerateUserIdentityAsync(UserManager manager) { // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie); // Add custom user […]

具有特殊字符的ASP.NET MVC标识电子邮件/用户名

通过Web API使用“xxx-yyy@gmail.com”等电子邮件注册帐户时,Fiddler会返回以下错误。 请注意,电子邮件也用于用户名,因此两个字段都相同 。 但它在注册MVC本身时有效。 ExceptionMessage =用户创建失败 – 身份exception。 错误是: 用户名xx-yyy@gmail.com无效,只能包含字母或数字。 用户对象 var newUser = new ApplicationUser { UserName = user.Email, Email = user.Email }; IdentifyConfig.cs public static ApplicationUserManager Create(IdentityFactoryOptions options, IOwinContext context) { var manager = new ApplicationUserManager(new UserStore(context.Get())); // Configure validation logic for usernames manager.UserValidator = new UserValidator(manager) { RequireUniqueEmail = true, AllowOnlyAlphanumericUserNames […]

ASP.net身份:如何获取当前的IdentityUser(ApplicationUser)? UserManager.FindById在哪里?

我从VS2013中的ASP.net默认模板开始。 我想获取当前的用户对象。 这可以在不直接访问数据库的情况下实现。 在文档中,这看起来非常简单: http : //blogs.msdn.com/b/webdev/archive/2013/10/16/customizing-profile-information-in-asp-net-identity-in-vs-2013 -templates.aspx 所以它应该是 var currentUser = manager.FindById(User.Identity.GetUserId()); 但是缺少FindById! 几个小时后,我一直在尝试使用FindByIdAsync。 但我想我得到了死锁。 public class UserManager : UserManager { public UserManager() : base(new UserStore(new ApplicationDbContext())) { } public async System.Threading.Tasks.Task GetCurrentUser() { var user = await FindByIdAsync(HttpContext.Current.User.Identity.Name); return user; } } 呼唤的主题: private IdentityUser_CurrentUser; protected IdentityUser CurrentUser { get { if (_CurrentUser […]

ASP.NET Identity扩展方法以访问用户属性

我可以扩展方法来访问用户属性吗? 有一些方法,如: User.Identity.GetUserId() User.Identity.GetUserName() 可以从视图和控制器访问。 我想用以下方法扩展此function: User.Identity.GetUserPhoneNumber() User.Identity.GetUserLanguaje()

即使删除用户,ASP.Net Identity Identity.IsAuthenticated仍然是正确的

我在下面的示例代码后实现了ASP.Net Identity: https : //github.com/rustd/AspnetIdentitySample 在我的实现中,我检查用户是否经过身份validation – 这是从我的MVC控制器上的FilterAttribute调用的; 这个想法是我想确认他们在提供页面之前仍然是auth’ed。 所以在我的filter中,最终会调用以下代码: _authenticationManager.User.Identity.IsAuthenticated; _authenticationManager在这里: private IAuthenticationManager _authenticationManager { get { return _httpContext.GetOwinContext().Authentication; } } _httpContext被传递到我的identityProvider类的构造函数中。 现在 – 一旦我登录, _authenticationManager.User.Identity.IsAuthenticated; 按预期返回true 。 但是,在开发期间,我倾倒并重新播种了我的数据库,而没有添加用户。 如此有效,我删除了IdentityUser – 但是_authenticationManager.User.Identity.IsAuthenticated; STILL返回true 知道为什么会这样吗? 我只能假设它以某种方式检查cookie,而不是实际查看数据库。 它是否正确? 或者我搞砸了我的实施…..

如何在用户点击注销按钮后让用户登录系统并注销?

我正在使用microsoft asp.net身份的自定义实现,因为我有自定义表,这就是为什么我已经给出了我的所有方法IUserStore和IUserPasswordStore的自定义实现。 问题是当用户登录然后在10-15分钟后登录用户会话到期但我想要的是除非用户注销我想让用户登录系统。 码: public partial class Startup { public void ConfigureAuth(IAppBuilder app) { app.CreatePerOwinContext(ApplicationDbContext.Create); app.CreatePerOwinContext(ApplicationUserManager.Create); app.CreatePerOwinContext(ApplicationSignInManager.Create); app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, LoginPath = new PathString(“/Account/Login”), Provider = new CookieAuthenticationProvider { OnValidateIdentity = SecurityStampValidator.OnValidateIdentity( validateInterval: TimeSpan.FromMinutes(30), regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager)) } }); app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie); app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5)); } } 账户管理员: [Authorize] public class AccountController : […]