我使用此代码检查登录:
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
{
if (!ModelState.IsValid)
{
return View(model);
}
var user = await UserManager.FindByEmailAsync(model.Email);
if (user != null)
{
if (!await UserManager.IsEmailConfirmedAsync(user.Id))
{
ViewBag.errorMessage = "You must have a confirmed email to log on.";
return View("Error");
}
}
var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false);
switch (result)
{
case SignInStatus.Success:
return RedirectToLocal(returnUrl);
case SignInStatus.LockedOut:
return View("Lockout");
case SignInStatus.RequiresVerification:
return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe }); …Run Code Online (Sandbox Code Playgroud) 我在Web API 2项目中使用ASP.NET Identity 2.2,但我不确定如何连接使用Autofac的ISecureDataFormat<AuthenticationTicket>依赖项.AccountController
我试过这个:
builder.RegisterType<ISecureDataFormat<AuthenticationTicket>>()
.As<TicketDataFo??rmat>();
Run Code Online (Sandbox Code Playgroud)
并得到错误:
类型'Microsoft.Owin.Security.ISecureDataFormat`1 [Microsoft.Owin.Security.Authenticat ionTicket]'不能分配给服务'Microsoft.Owin.Security.DataHandler.TicketDataFormat'
我遇到的所有问题似乎都没有使用最新的ASP.NET身份稳定版本.
任何帮助是极大的赞赏.
asp.net dependency-injection autofac asp.net-web-api2 asp.net-identity-2
我试图显示从我的所有可用角色RoleManager中DropDownList,然后选择特定的角色,该用户的成员。对此的要求是用户只能担任一个角色(“用户、管理员或无访问权限”)。
当我获得角色列表并将它们分配给我的 ViewModel 时,当我尝试显示它们时出现错误,我收到一个错误:
无法从“System.Collections.Generic.IEnumberable<SiteName.Models.AppRole>”转换为“Systems.Collections.IEnumerable<System.Web.Mvc.SelectListItem>。
我是否需要创建一个 ViewModel 来获取 RoleName 和 RoleId,然后遍历我从 RoleManger 获得的角色列表并填充该 ViewModel 的列表以传递给我的视图?当我已经有一个继承自 IdentityRole 的类 (AppRole) 时,这似乎是额外的代码,它应该具有 Role.Name 和 Role.Id。
这是我用于编辑/显示用户的 ViewModel:
public class UserEditVM : BaseViewModel
{
public string Id { get; set; }
public string UserName { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
public string UserRole { get; set; }
public string RoleID { …Run Code Online (Sandbox Code Playgroud) 您好,我有一个使用 MVC 5 身份角色的 ASP MVC 应用程序,为了简单起见,我有 2 个身份角色(“管理员”和“员工”)。角色管理中的用户可以访问管理面板,在其中可以创建其他用户,而员工角色中的用户只能访问员工视图。我在将用户分配给角色并将[授权]应用于控制器方面没有问题。
我想在成功登录后将用户用户重定向到其相对视图,因此如果用户处于管理员角色,则会自动重定向到管理面板或视图,如果员工页面中的用户重定向到员工视图。
如何在我的登录控制器中应用它?谢谢
我试图使用EF 6从两个不同的表中获取数据,它是一个asp.net mvc 5项目,其中使用了Identity 2.0,但是当我加入两个表时,我得到两个实体的上下文不同的错误,但它不是,这是我的代码:
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DefaultConnection", throwIfV1Schema: false)
{
}
public DbSet<UserAccountStatus> UserAccountStatuss { get; set;}
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的linq查询:
var result = (from user in DbContext.Users
join accountStatus in DbContext.UserAccountStatuss on user.Id equals accountStatus.UserId
where user.Email == email
select accountStatus.AccountEnabled).FirstOrDefault();
Run Code Online (Sandbox Code Playgroud)
我的DbContext属性:
public ApplicationDbContext DbContext
{
get
{
return _dbContext ?? ApplicationDbContext.Create();
}
private set
{
_dbContext = value;
}
}
Run Code Online (Sandbox Code Playgroud)
确切的错误是:
指定的LINQ表达式包含对与不同上下文关联的查询的引用.
这不是重复,我已经看到其他问题,在那些用户实际上尝试不同的上下文,但在我的情况下,我有一个.
我正在使用带有Identity 2框架的ASP.NET MVC5 ,数据库优先
我正在尝试AspNetRoles通过添加名为MyCustomColumn的列进行自定义
但是,我的应用程序崩溃是因为:
无效的列名称识别器
在SO和网络上的其他地方有很多资源,但大多数都使用CodeFirst方法,我不能在我的应用程序中使用它们.
怎么处理呢?
asp.net-mvc asp.net-roles discriminator asp.net-mvc-5 asp.net-identity-2