asp.net-mvc-5

How to inject UserManager & SignInManager

ⅰ亾dé卋堺 提交于 2019-12-17 10:29:13
问题 I am trying to figure out how to inject UserManager and SignInManager. I have installed Ninject in my application and I am using it in the following manner: Please consider this to be a brand new project. Inside Startup.cs I have the following: public partial class Startup { public void Configuration(IAppBuilder app) { ConfigureAuth(app); app.UseNinjectMiddleware(CreateKernel); } private static IKernel CreateKernel() { var kernel = new StandardKernel(); kernel.Load(Assembly

Asp.net Identity Validation Error

纵然是瞬间 提交于 2019-12-17 10:24:18
问题 I want integrate IdentityContext with mydbcontext but i am taking this error One or more validation errors were detected during model generation: Ivdb.Dal.Concrete.EFCodeFirst.IdentityUserLogin: : EntityType 'IdentityUserLogin' has no key defined. Define the key for this EntityType. Ivdb.Dal.Concrete.EFCodeFirst.IdentityUserRole: : EntityType 'IdentityUserRole' has no key defined. Define the key for this EntityType. IdentityUserLogins: EntityType: EntitySet 'IdentityUserLogins' is based on

The model backing the 'ApplicationDbContext' context has changed since the database was created

二次信任 提交于 2019-12-17 10:15:17
问题 First of all I have not seen this error anywhere else and I guess its not a replicate so please read the whole situation first. Every thing was working just fine then I tried to update one of my model classes ( the App class and the update is now left commented ) which I will be listing below and boom I had this ugly error. The model backing the 'ApplicationDbContext' context has changed since the database was created. Consider using Code First Migrations to update the database (http://go

Creating Roles in Asp.net Identity MVC 5

你离开我真会死。 提交于 2019-12-17 10:10:01
问题 There is very little documentation about using the new Asp.net Identity Security Framework. I have pieced together what I could to try and create a new Role and add a User to it. I tried the following: Add role in ASP.NET Identity which looks like it may have gotten the info from this blog: building a simple to-do application with asp.net identity and associating users with to-does I have added the code to a Database Initializer that is run whenever the model changes. It fails on the

There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key “key”

时间秒杀一切 提交于 2019-12-17 10:02:16
问题 My code is like this namespace DiagnosisApp.Models { public class ProcedurePrice { public int ID { get; set; } public int DepartmentID { get; set; } public int ProcedureID { get; set; } public int InsuranceProviderID { get; set; } public int ProcedureCategoryID { get; set; } public int ProcedureSubCategoryID { get; set; } [ForeignKey("ID")] public virtual Department Department { get; set; } [ForeignKey("ID")] public virtual InsuranceProvider InsuranceProvider { get; set; } [ForeignKey("ID")]

aspnet identity invalid token on confirmation email

南楼画角 提交于 2019-12-17 09:45:09
问题 I'm trying to confirm an account but I'm getting "invalid token." error. Here's what I'm trying: var code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); var callbackUrl = Url.Action("ConfirmacaoEmail", "Usuario", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); await UserManager.SendEmailAsync(user.Id, "Ativação de Conta", user.GetEmailAtivacao(model.Nome, callbackUrl)); if I call UserManager.ConfirmEmailAsync after this code, I can confirm the account.

Get UserID of logged-in user in Asp.Net MVC 5

别等时光非礼了梦想. 提交于 2019-12-17 09:11:14
问题 I'm relatively new to ASP.Net MVC and try to use the built-in user login functionality now. I'm able to register an user in the registration view. If I try to login with the created user this also works. I'm redirected to the master page. But I'm not able to get the UserID of the current user. I tried my code in the HomeController and in the AccountController, but both didn't work. The statement in the first line returns always null. var userID = User.Identity.GetUserId(); if (!string

Get UserID of logged-in user in Asp.Net MVC 5

假如想象 提交于 2019-12-17 09:11:11
问题 I'm relatively new to ASP.Net MVC and try to use the built-in user login functionality now. I'm able to register an user in the registration view. If I try to login with the created user this also works. I'm redirected to the master page. But I'm not able to get the UserID of the current user. I tried my code in the HomeController and in the AccountController, but both didn't work. The statement in the first line returns always null. var userID = User.Identity.GetUserId(); if (!string

How do I mock User.Identity.GetUserId()?

↘锁芯ラ 提交于 2019-12-17 07:25:32
问题 I am trying to unit test my code which includes the line: UserLoginInfo userIdentity = UserManager.GetLogins(User.Identity.GetUserId()).FirstOrDefault(); I'm just stuck on one bit as I can't get: User.Identity.GetUserId() to return a value. I have been trying the following in the set-up of my controller: var mock = new Mock<ControllerContext>(); mock.Setup(p => p.HttpContext.User.Identity.GetUserId()).Returns("string"); But it gives an error of "NotSupportedException was unhandled by user

ASP.NET Identity change password

霸气de小男生 提交于 2019-12-17 06:28:56
问题 I need ability to change password for user by admin. So, admin should not enter a current password of user, he should have ability to set a new password. I look at ChangePasswordAsync method, but this method requires to enter old password. So, this method is not appropriate for this task. Therefore I have made it by the following way: [HttpPost] public async Task<ActionResult> ChangePassword(ViewModels.Admin.ChangePasswordViewModel model) { var userManager = HttpContext.GetOwinContext()