正如标题所说:无论如何将用户(及其密码!)从旧的成员资格提供者导入新的身份系统?
我可以在旧表格布局中看到有一个Password和PasswordSalt列,但在新的IdentityUsers表中只有一个PasswordHash列.我希望有一种方法可以将用户从旧系统复制到新系统,而无需创建新密码.
没有代码,因为我不知道这是否可能.
是否有可能在Db(此时创建)中使用角色Seed()作为Enum或类似的东西,以便不使用记住所有角色等,而是可以使用intellisense?
如果有可能你能告诉我怎么样?
我有两个ASP.NET标识使用的类.一个是用户列表的支持类,另一个是角色.在数据库中有三个表.AspNetUsers,AspNetRoles和AspNetUserRoles.由于它们在实体框架中的映射方式,这三个映射到两个类:
public partial class AspNetUser
{
public AspNetUser()
{
this.AspNetUserClaims = new List<AspNetUserClaim>();
this.AspNetUserLogins = new List<AspNetUserLogin>();
this.AspNetRoles = new List<AspNetRole>();
}
public int Id { get; set; }
public virtual ICollection<AspNetRole> AspNetRoles { get; set; }
public virtual ICollection<AspNetUserClaim> AspNetUserClaims { get; set; }
public virtual ICollection<AspNetUserLogin> AspNetUserLogins { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
和
public partial class AspNetRole
{
public AspNetRole()
{
this.AspNetUsers = new List<AspNetUser>();
}
public int Id { get; set; }
public string Name { get; …Run Code Online (Sandbox Code Playgroud) 我成功地在我的用户名中获取了非字母数字字符,我现在遇到的问题是当我尝试将角色分配给用户时它会抛出无效的用户名错误.它说"只能包含字母和数字.
这是我添加的用于允许用户名中的字符;
public AccountController(UserManager<ApplicationUser> userManager)
{
UserManager = userManager;
var userValidator = UserManager.UserValidator as UserValidator<ApplicationUser>;
userValidator.AllowOnlyAlphanumericUserNames = false;
}
Run Code Online (Sandbox Code Playgroud)
这是我收到错误的地方;
public bool AddUserToRole(string userId, string roleName)
{
var um = new UserManager<ApplicationUser>(
new UserStore<ApplicationUser>(new ApplicationDbContext()));
var idResult = um.AddToRole(userId, roleName);
return idResult.Succeeded;
Run Code Online (Sandbox Code Playgroud)
idResult.Erorrs [0] =" 用户名J.Blow无效,只能包含字母或数字. "
为什么我得到这个.我是否需要在其他地方更改用户名的变体?
提前致谢.
克林特
我正在asp.net mvc中开发一个Web应用程序。我的应用程序使用多个数据库。正在使用的数据库取决于登录的用户。我在两个级别上管理登录:
示例:在“主”数据库中,我在用户表中有一条记录,其中包含:-用户名=用户1-databaseToUse =“ specificDb1”
对于同一个用户,在名为“ specificDb1”的“特定”数据库中,我在用户表中有一条记录,其中包含管理用户身份验证所需的全部内容。
我想要实现的是:
第1点和第2点没有问题。问题出在第3点。我对(主数据库和特定数据库)数据库都使用EntityFramework 6 Code First。
关于身份的配置部分,我在Startup.Auth.cs中看到:
app.CreatePerOwinContext(ApplicationDbContext.Create);
app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);
Run Code Online (Sandbox Code Playgroud)
我应该更改身份配置中的某些内容吗?
提前致谢。
我有一个带有web api,web应用程序和Xamarin应用程序的项目.它们都应该使用存储在AspNetCore库中的相同数据模型.我想将EF Core用于数据库,我有一个Db管理项目(也是一个AspNetCore库),引用了包含上下文和设置的EF Core.web api是引用此Db Managing项目的唯一项目,因为它处理所有数据库访问.所有其他应用程序都在联系web api进行数据交互.
我的问题:我想使用AspNetCore.Identity进行用户管理,但是当使用AspNetCore.Identity时,Xamarin Apps无法引用数据模型.我怎么解决这个问题?
architecture entity-framework xamarin asp.net-identity asp.net-core
一切正常,直到我介绍身份.
我将上下文类更改为:
public partial class VisualJobsDbContext : IdentityDbContext<ApplicationUser>
{
private IConfigurationRoot _config;
public VisualJobsDbContext() { }
public VisualJobsDbContext(IConfigurationRoot config, DbContextOptions options) : base(options)
{
_config = config;
}...
Run Code Online (Sandbox Code Playgroud)
我有一个在表单中声明的通用存储库:
public abstract class GenericRepository<C,T> : IGenericRepository<T> where T : class where C : IdentityDbContext<ApplicationUser>, new()
{
private C _entities = new C();
private VisualJobsDbContext context;
private DbSet<T> dbSet;
public GenericRepository(VisualJobsDbContext context)
{
this.context = context;
this.dbSet = context.Set<T>();
}....
Run Code Online (Sandbox Code Playgroud)
错误发生在
this.dbSet = context.Set <>();
它第一次被击中.我的OnModelCreating方法确实被调用了.我试图从我的MVC应用程序访问的页面不需要登录,因为它是一般页面,但是会有需要登录的区域.但是,在错误之前,我没有得到我的控制器Constructor方法.注册我的服务:
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<VisualJobsDbContext>()
.AddDefaultTokenProviders();
Run Code Online (Sandbox Code Playgroud)
我可以踩到这个.
我缺少什么想法?我看过这个 …
当我请求[授权]装饰的控制器操作而不是重定向到登录页面时,我收到401错误.
这是一个使用IIS Express上运行的身份模板的.net核心mvc应用程序.
当我从program.cs运行应用程序时,重定向到登录工作正常.我已经为cookie身份验证添加了明确的指示,以便在配置和服务部分使用/ Account/Login重定向,以及配置Identity来执行此重定向.
我无法让它发挥作用.下面是我的StartUp类,我应该更改什么才能使它在IIS express中运行?:
public class Startup
{
private MapperConfiguration _mapperConfiguration { get; set; }
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);
if (env.IsDevelopment())
{
// For more details on using the user secret store see http://go.microsoft.com/fwlink/?LinkID=532709
builder.AddUserSecrets();
}
builder.AddEnvironmentVariables();
Configuration = builder.Build();
_mapperConfiguration = new MapperConfiguration(cfg =>
{
cfg.AddProfile(new AutoMapperProfileConfiguration());
});
}
public IConfigurationRoot Configuration { get; }
// This method gets called by the …Run Code Online (Sandbox Code Playgroud) redirect http-status-code-401 iis-express asp.net-identity asp.net-core-mvc
我有一个MVC5项目,根据用户的角色显示/隐藏了一些菜单.另一方面,我通过HTML字符串使用DataGrid和一些图标进行Details,Update和Delete操作,并且需要在此HTML字符串中实现User.IsInRole().我怎样才能做到这一点?
查看(剃刀):
<script>
var table;
$(document).ready(function () {
table = $('#dtbStudent')
.DataTable({
//code omitted for brevity
"columnDefs": [
{
"targets": 6,
"data": "download_link",
"render": function (data, type, full, meta) {
return '<a title="Details" id="lnkStudentDetails"></a>' +
'<a title="Edit" id="lnkStudentEdit" ></a>' +
'<a title="Delete" id="lnkStudentDelete" ></i></a>';
}
}
]
});
});
//EventListener ################################################
$(document).on('click', '#lnkStudentDetails', function () {
//!!! It is also possible for me to check the roles at here
and return false & tooltip message
//opens Details modal
});
$(document).on('click', …Run Code Online (Sandbox Code Playgroud) 我在.Net 4.6.2/MVC5中更新ASP.Net Identity 2.2.1的声明时遇到问题.更新声明后,它通常会向浏览器发送更新的cookie,一切正常,但有时没有设置cookie标头发送到浏览器.
我无法确定何时发生任何模式,而不是在发生故障时,服务器正在发送
Persistent-Auth: true
Run Code Online (Sandbox Code Playgroud)
会话中每个响应的http标头值.我不知道是什么原因导致此标头值被设置并且它有时会出现在会话中间,一旦它开始发送它,它将被发送到会话的其余部分并且尝试更新声明将永远不会再次为该会话工作.
据我所知,我在每次调用ASP.Net标识时都将isPersistent参数硬编码为false,我看不到任何可能与此标头相关的内容.
我用来更新声明的代码是
public static void UpdateClaims(List<Claim> claims)
{
var authenticationManager = HttpContext.Current.GetOwinContext().Authentication;
var newIdentity = new ClaimsIdentity(HttpContext.Current.User.Identity);
foreach (Claim claim in claims)
{
Claim oldClaim = newIdentity.FindFirst(claim.Type);
if (oldClaim != null && oldClaim.Type != "")
{
newIdentity.RemoveClaim(oldClaim);
}
newIdentity.AddClaim(claim);
}
authenticationManager.AuthenticationResponseGrant = new AuthenticationResponseGrant
(new ClaimsPrincipal(newIdentity), new AuthenticationProperties { IsPersistent = false });
}
Run Code Online (Sandbox Code Playgroud)
这是从MVC动作方法调用的.
有没有人有什么建议可能会出问题,甚至只是一个起点在哪里看?我不知道是什么导致持久性auth标头,但它看起来与问题有关; 无论是问题的原因还是症状,我都不知道.
我正在使用ASP.Net Identity 2.2.1和.Net 4.6.2.我在Windows Server 2012R2上运行,IE11,Chrome和Firefox似乎也出现了这个问题.我正在使用Fiddler 4.6.3来查看http标头/响应.
更新:我注意到只有在启用Windows身份验证时才会出现问题.我的服务器有一个允许用户名/密码,Windows身份验证或两者的设置(用户可以选择使用用户名/密码以其他用户身份登录).当使用windows auth时,我最初使用Windows对用户进行身份验证,然后设置一个cookie,然后我将其用于会话中的所有未来请求.如果禁用了Windows身份验证,则更新此类声明始终有效.如果启用了Windows身份验证,则更新声明通常有效.
asp.net-identity ×10
c# ×7
asp.net-mvc ×5
asp.net ×4
architecture ×1
asp.net-core ×1
enums ×1
iis-express ×1
intellisense ×1
linq ×1
razor ×1
redirect ×1
xamarin ×1