标签: asp.net-identity

错误使用泛型类型 AspNet.Identity.usermanager<Tuser> 需要 1 种类型的参数?

我在尝试使用 UserManager.CreateAsync(user, reg.password) 代码时收到此错误。请帮忙。还有一件事我安装了包 aspnet.identity.core 包。但我不能参考它。当我尝试使用 Using 引用它时,我找不到包。

        if (ModelState.IsValid)
        {
            var user = new ApplicationUser() { UserName = reg.username };
            var result = await UserManager.CreateAsync(user, reg.password);
              if (result.Succeeded)
            {
                await SignInAsync(user, isPersistent: false);
                return RedirectToAction("Index", "Account");
            }
            else
            {
                AddErrors(result);
            }
Run Code Online (Sandbox Code Playgroud)

.net c# asp.net asp.net-mvc-4 asp.net-identity

0
推荐指数
1
解决办法
4784
查看次数

安全地允许一次性访问 ASP.NET MVC 5 应用程序的一部分

我正在构建的应用程序的一部分要求管理员用户可以让员工访问应用程序的一个页面来执行任务。员工完成该任务后,他们没有理由返回应用程序。

此应用程序是在线托管的,因此需要通过登录来保护员工访问权限。

我的问题是,向只会使用系统一次的用户提供登录帐户的最佳方法是什么?

在我看来,我有两个选择:

  1. 为管理员用户提供一个永久的员工登录帐户,该帐户可以为每个员工重复使用(我需要为每个员工提供一个额外的密码,以便系统可以查找并查看他们的真实身份)

  2. 在需要访问时为每个员工创建一个登录帐户,然后在使用后删除该登录帐户。对于这个用户名,我会将一个常用词(例如公司名称)与一个唯一的 ID(可能是他们任务的 ID)连接起来

选项 2 似乎在安全性方面最有意义。这种方法是否存在任何缺陷,或者是否有其他解决方案?

asp.net security authentication asp.net-mvc asp.net-identity

0
推荐指数
1
解决办法
1165
查看次数

/connect/userinfo 返回给我一个 403 forbidden in identityserver4

我正在使用 IdentityServer4 提供的示例应用程序: Quickstart6_AspNetIdentity.sln 使用 ro.client,我可以获得令牌。

在此处输入图片说明

但是当我使用相同的令牌获取用户信息时,我在同一个示例中收到 403 Forbidden 错误。按原样使用样品。不知道是bug 还是参数中遗漏了什么。遵循文档中提到的所有参数:https : //identityserver4.readthedocs.io/en/release/endpoints/userinfo.html

oauth-2.0 asp.net-identity identityserver4

0
推荐指数
1
解决办法
2200
查看次数

防止在asp.net core 2中多次登录

再会,

由于IdentityOption 中没有SecurityStampValidationInterval,我如何验证安全戳以防止Asp.Net Core 2 中的单个用户多次登录。

提前致谢。

core asp.net-identity

0
推荐指数
1
解决办法
1871
查看次数

在AspNetUsers中存储其他用户属性

将属性扩展/添加到AspNetUsers表中的最佳做法是什么?(.Net Core 2.0)

1)您可以在AspNetUsers表中添加其他属性

2)您可以将内容放入声明中

3)您可以在属性中放置对另一个表的引用

4)您可以使用user.id并将其与更多数据一起存储在另一个表中

那么最佳实践是什么?

.net asp.net-mvc asp.net-identity .net-core asp.net-core-2.0

0
推荐指数
1
解决办法
67
查看次数

未在数据库中创建身份的 Asp.net 核心表

当我在其他示例项目中看到时,为支持数据库中的 Identity 创建的表数量很大(例如 AspNetRoles、AspNetUserClaims 等),但在我的情况下,当我进行迁移和更新时仅用户表已经被创造了。是什么原因?这是我在启动、dbcontext 和我的班级用户中的代码:

public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();
            services.AddSession();
            services.AddMemoryCache();
            services.AddDbContext<ApplicationDbContext>( options =>
                             options.UseSqlServer(Configuration["Data:photoarchiver:ConnString"]));
            services.AddIdentity<User, IdentityRole > (
                opts => {
                    opts.Password.RequireDigit = false;
                    opts.Password.RequiredLength = 7;
                    opts.Password.RequireLowercase = true;
                    opts.Password.RequireUppercase = false;
                    opts.Password.RequireNonAlphanumeric = false;
                }).AddEntityFrameworkStores<ApplicationDbContext>();
        }
Run Code Online (Sandbox Code Playgroud)

类 DbContext:

public class ApplicationDbContext : DbContext
    {
        public ApplicationDbContext(DbContextOptions options) : base(options)
        {

        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<User>().ToTable("Users");
            modelBuilder.Entity<User>().HasMany(u => u.Photos).WithOne(i => i.User);

            modelBuilder.Entity<Photo>().ToTable("Photos");
            modelBuilder.Entity<Photo>().HasOne(i => i.User).WithMany(u => u.Photos);

            modelBuilder.Entity<Category>().ToTable("Categories");

        }

        public DbSet<Photo> Photos …
Run Code Online (Sandbox Code Playgroud)

database asp.net-identity

0
推荐指数
1
解决办法
1231
查看次数

如何删除默认的ASP.NET核心标识端点?

假设我想编写自己的Login,Logout端点及其Views

但出于某种原因,我正努力去除现有的端点

每当我删除可能与这些端点关联的内容时,它们都会重新创建并返回其默认视图.

基本上我想删除从ASP.NET Core Identity生成的那些默认端点/视图

关于如何实现这一点的任何想法?

        "Templates/Identity/Pages/Account/Account.AccessDenied.cs.cshtml",
        "Templates/Identity/Pages/Account/Account.AccessDenied.cshtml",
        "Templates/Identity/Pages/Account/Account.ConfirmEmail.cs.cshtml",
        "Templates/Identity/Pages/Account/Account.ConfirmEmail.cshtml",
        "Templates/Identity/Pages/Account/Account.ExternalLogin.cs.cshtml",
        "Templates/Identity/Pages/Account/Account.ExternalLogin.cshtml",
        "Templates/Identity/Pages/Account/Account.ForgotPassword.cs.cshtml",
        "Templates/Identity/Pages/Account/Account.ForgotPassword.cshtml",
        "Templates/Identity/Pages/Account/Account.ForgotPasswordConfirmation.cs.cshtml",
        "Templates/Identity/Pages/Account/Account.ForgotPasswordConfirmation.cshtml",
        "Templates/Identity/Pages/Account/Account.Lockout.cs.cshtml",
        "Templates/Identity/Pages/Account/Account.Lockout.cshtml",
        "Templates/Identity/Pages/Account/Account.Login.cs.cshtml",
        "Templates/Identity/Pages/Account/Account.Login.cshtml",
        "Templates/Identity/Pages/Account/Account.LoginWith2fa.cs.cshtml",
        "Templates/Identity/Pages/Account/Account.LoginWith2fa.cshtml",
        "Templates/Identity/Pages/Account/Account.LoginWithRecoveryCode.cs.cshtml",
        "Templates/Identity/Pages/Account/Account.LoginWithRecoveryCode.cshtml",
        "Templates/Identity/Pages/Account/Account.Logout.cs.cshtml",
        "Templates/Identity/Pages/Account/Account.Logout.cshtml",
        "Templates/Identity/Pages/Account/Account.Register.cs.cshtml",
        "Templates/Identity/Pages/Account/Account.Register.cshtml",
        "Templates/Identity/Pages/Account/Account.ResetPassword.cs.cshtml",
        "Templates/Identity/Pages/Account/Account.ResetPassword.cshtml",
        "Templates/Identity/Pages/Account/Account.ResetPasswordConfirmation.cs.cshtml",
        "Templates/Identity/Pages/Account/Account.ResetPasswordConfirmation.cshtml",
        "Templates/Identity/Pages/Account/Account._ViewImports.cshtml",
        "Templates/Identity/Pages/Account/Manage/Account.Manage.ChangePassword.cs.cshtml",
        "Templates/Identity/Pages/Account/Manage/Account.Manage.ChangePassword.cshtml",
        "Templates/Identity/Pages/Account/Manage/Account.Manage.DeletePersonalData.cs.cshtml",
        "Templates/Identity/Pages/Account/Manage/Account.Manage.DeletePersonalData.cshtml",
        "Templates/Identity/Pages/Account/Manage/Account.Manage.Disable2fa.cs.cshtml",
        "Templates/Identity/Pages/Account/Manage/Account.Manage.Disable2fa.cshtml",
        "Templates/Identity/Pages/Account/Manage/Account.Manage.DownloadPersonalData.cs.cshtml",
        "Templates/Identity/Pages/Account/Manage/Account.Manage.DownloadPersonalData.cshtml",
        "Templates/Identity/Pages/Account/Manage/Account.Manage.EnableAuthenticator.cs.cshtml",
        "Templates/Identity/Pages/Account/Manage/Account.Manage.EnableAuthenticator.cshtml",
        "Templates/Identity/Pages/Account/Manage/Account.Manage.ExternalLogins.cs.cshtml",
        "Templates/Identity/Pages/Account/Manage/Account.Manage.ExternalLogins.cshtml",
        "Templates/Identity/Pages/Account/Manage/Account.Manage.GenerateRecoveryCodes.cs.cshtml",
        "Templates/Identity/Pages/Account/Manage/Account.Manage.GenerateRecoveryCodes.cshtml",
        "Templates/Identity/Pages/Account/Manage/Account.Manage.Index.cs.cshtml",
        "Templates/Identity/Pages/Account/Manage/Account.Manage.Index.cshtml",
        "Templates/Identity/Pages/Account/Manage/Account.Manage.ManageNavPages.cshtml",
        "Templates/Identity/Pages/Account/Manage/Account.Manage.PersonalData.cs.cshtml",
        "Templates/Identity/Pages/Account/Manage/Account.Manage.PersonalData.cshtml",
        "Templates/Identity/Pages/Account/Manage/Account.Manage.ResetAuthenticator.cs.cshtml",
        "Templates/Identity/Pages/Account/Manage/Account.Manage.ResetAuthenticator.cshtml",
        "Templates/Identity/Pages/Account/Manage/Account.Manage.SetPassword.cs.cshtml",
        "Templates/Identity/Pages/Account/Manage/Account.Manage.SetPassword.cshtml",
        "Templates/Identity/Pages/Account/Manage/Account.Manage.ShowRecoveryCodes.cs.cshtml",
        "Templates/Identity/Pages/Account/Manage/Account.Manage.ShowRecoveryCodes.cshtml",
        "Templates/Identity/Pages/Account/Manage/Account.Manage.TwoFactorAuthentication.cs.cshtml",
        "Templates/Identity/Pages/Account/Manage/Account.Manage.TwoFactorAuthentication.cshtml",
        "Templates/Identity/Pages/Account/Manage/Account.Manage._Layout.cshtml",
        "Templates/Identity/Pages/Account/Manage/Account.Manage._ManageNav.cshtml",
        "Templates/Identity/Pages/Account/Manage/Account.Manage._StatusMessage.cshtml",
        "Templates/Identity/Pages/Account/Manage/Account.Manage._ViewImports.cshtml",
        (...)
Run Code Online (Sandbox Code Playgroud)

c# asp.net-identity asp.net-core-mvc asp.net-core

0
推荐指数
1
解决办法
333
查看次数

身份的方案名称是什么?

假设我使用以下内容:

services.AddIdentity<User, UserRole>()
        .AddEntityFrameworkStores<AppDbContext>();
Run Code Online (Sandbox Code Playgroud)

设置的认证方案名称是什么?我在任何文档中都找不到。我试图与名称寻找类IdentityAuthenticationDefaultsIdentityDefaults却一无所获。我尝试过“ Cookies”,但未设置为此。该应用程序运行良好,因此肯定设置了一些方案名称。

c# asp.net-identity asp.net-core asp.net-core-identity .net-core-authorization

0
推荐指数
1
解决办法
252
查看次数

问题添加 IdentityDbContext

我正在使用Asp Net core 3并尝试添加身份核心。当我添加IdentityDbContext它时会出现错误,如果我更改IdentityDbContextDbContext错误就消失了。同样的问题是当我尝试添加SQL severusingIdentityDbContext但在 using 时没有错误DbContext。我收到以下错误“没有从IdentityDbContext到的隐式引用转换Microsoft.EntityFrameworkCore.DbContext点击查看错误 我添加了以下 NuGet 包Microsoft.AspNetCore.Identity.EntityFrameworkCoreMicrosoft.EntityFrameworkCore.Sqlserver。请帮忙。

c# asp.net-identity asp.net-core asp.net-core-identity

0
推荐指数
1
解决办法
61
查看次数

使用 .AddIdentityServerJwt() 时,.NET Core Razor Pages 应用程序的身份验证不适用于没有“/Identity”路由的视图

使用 .NET Core 3.1 框架,我尝试使用以下设置配置 Web 平台:

  • Razor Pages 应用程序,充当平台的登陆页面,具有平台广告、cookie 同意、隐私政策、联系人以及身份附带的页面(例如登录、注册、管理帐户)等功能/页面。
  • Razor Pages 应用程序的身份验证以标准身份方式执行。
  • Angular SPA,只有在用户登录后才能访问。
  • 使用 Identity Server 进行 OIDC 配置,以便向 Angular SPA 添加身份验证和授权。

所有这三个组件(Razor Pages + Angular + Identity Server)都捆绑到一个 .NET Core Web 项目中。我还搭建了 Identity 框架,以便能够自定义页面的外观和行为。

我几乎能够按照我想要的方式配置应用程序,方法是基本上混合 Razor Pages 选项的启动模板代码(用户帐户存储在本地)和 Angular 模板选项(用户帐户存储在本地)以及一些尝试、错误和调查。

我的申请目前的状态是:

  1. 用户登录 Razor Pages 应用程序。
  2. 登录成功,导航栏显示邮件。
  3. 当我们导航到 SPA 时,我的 Angular 应用程序尝试静默登录并成功:

本地主机:5001/Dashboard(Angular SPA 主路由)

在此输入图像描述

  1. 如果我们导航到 Razor Pages 应用程序中没有路由的部分/Identity(仅用于带有身份的页面),则 cookie 似乎不再包含正确的信息,并且我在这些路由中没有会话。这意味着,例如,如果我使用SignInManager.IsSignedIn(User)仅显示受 保护的管理页面的导航选项options.Conventions.AuthorizePage($"/Administration"),如果我位于具有身份路由的 URL 中,则将显示导航选项卡,否则将显示不显示:

本地主机:5001/身份/帐户/登录

在此输入图像描述

localhost:5001(Razor Pages 应用程序主路由)

在此输入图像描述

  1. 但是,即使当我位于具有路由的 URL …

asp.net-identity openid-connect .net-core asp.net-core identityserver4

0
推荐指数
1
解决办法
691
查看次数