asp.net-identity-2

How can I get a users role inside a WebAPI method without a lookup to the AspNetUserRoles table?

随声附和 提交于 2019-11-28 16:19:47
问题 I have a stored procedure that updates status. Depending on the role of the user the stored procedure has code that may or may not allow the status change. For this reason I need to pass a role name into a stored procedure. My role name is stored on the client in my javascript code but of course I need a second check on the server. Each user has only one of three roles and when requesting an update of status I can call one of three methods depending on the role that the client has. Here's

ASP.NET MVC 5 : Endless redirect to the login page using the site template

时光总嘲笑我的痴心妄想 提交于 2019-11-28 13:34:09
I just started using ASP.NET MVC 5 (I already used the previous versions quite a lot) and I have a very weird issue: I created a new website using the Visual Studio 2013 (fully updated) ASP.NET template. For the template options I selected the MVC template, "Individual User Accounts" authentication type, no cloud hosting, and no other components than the core MVC library. After I validate the options, I update all the NuGet packages. And after that I press F5 (without opening or modifying any of the new project files). The browser opens only to show an error page, because of an endless

UserManager.GetRoles doesn't work after extending the IdentityUserRole in MVC 5 Dot Net Identity

点点圈 提交于 2019-11-28 11:58:49
问题 I have extended the IdentityUserRole by adding a foreign key column and now I am unable to Authorize or retrieve Roles information. Could please anyone help me in sorting out this issue. My IdentityUserRole has a foreign key column from AspNetApplications table and the IdentityUserRole extension is as follow public class AspNetUserRoles : IdentityUserRole { [Key] public string ApplicationId { get; set; } [ForeignKey("ApplicationId")] public AspNetApplications AspNetApplications { get; set; }

How can customize Asp.net Identity 2 username already taken validation message?

泪湿孤枕 提交于 2019-11-28 09:41:50
How can i customize Asp.net Identity 2 username already taken validation message(Name XYZ is already taken.)? Thanks Well, I didn't find any simple solution to this issue. And by simple i mean modifying some message in a attribute/model/controller. One possible solution could be: After executing var result = await UserManager.CreateAsync(user, model.Password); In case that result is not successful you can check it's Errors property for the "Name XYZ is already taken." pattern and replace it with your custom message. Another solution (this is my preferred way) is to write a custom

Identity 2.0: Creating custom ClaimsIdentity eg: User.Identity.GetUserById<int>(int id) for Per Request Validation

纵饮孤独 提交于 2019-11-28 09:29:47
See this similar question: Need access more user properties in User.Identity I would like to create custom authentication methods to use with my Razor Views that allows easy access IdentityUser properties relational to the User.Identity object but I am not sure how to go about it. I want to create several custom extensions similar to User.Identity.GetUserName() , User.Identity.GetUserById() , etc... instead of using this ViewContextExtension method. My Authentication type is currently the default type DefaultAuthenticationTypes.ApplicationCookie from VS2013 MVC5 template. As Shoe stated, I

ASP.Net Identity 2 - custom response from OAuthAuthorizationServerProvider

一世执手 提交于 2019-11-28 08:48:38
This question is continuation of my previous one: ASP.Net Identity 2 login using password from SMS - not using two-factor authentication I've build my custom OAuthAuthorizationServerProvider to support custom grant_type. My idea was to create grant_type of sms that will allow user to generate one-time access code that will be send to his mobile phone and then user as password when sending request with grant_type of password. Now after generating, storing and sending via SMS that password I'd like to return custom response, not token from my GrantCustomExtension. public override async Task

Trying to change table names in ASP.NET Identity 2.0

ⅰ亾dé卋堺 提交于 2019-11-28 08:39:18
I want to change the names of the tables used by ASP.NET Identity 2.0. I've seen various similar questions but nothing that solves my problem. For instance this type of solution: http://www.goatly.net/customizing-table-names-for-identitydbcontextwithcustomuser-data-contexts seems to depend on Code First(?). At any rate implementing OnModelCreating does nothing for me. I've basically renamed the AspNetUsers and similar tables to my own names and want to be able to use these. I have an existing EF context (MyContext) that I want to use, so I modified it to derive from IdentityDbContext (editing

Creating Asp.net Identity user in Seed method of Db Initializer

∥☆過路亽.° 提交于 2019-11-28 07:35:11
I have created my data layer with EF 6 code first and I am populating the db through Seed method of EvInitializer class inheriting from DropCreateDatabaseIfModelChanges . The implementation of Seed method is protected override void Seed(EvContext context) { //Add other entities using context methods ApplicationUserManager manager = new ApplicationUserManager(new UserStore<ApplicationUser>(context)); var user = new ApplicationUser { Email = "admin@myemail.com" ,UserName = "admin@myemail.com"}; var result = await manager.CreateAsync(user, "Temp_123");//this line gives error. obviously await

How to login using email in identity 2?

北城余情 提交于 2019-11-28 07:34:33
In MVC5 Identity 2 SignInManager.PasswordSignInAsync take user name for login. var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false); but my user name and email are not same. but i want to email address for login.So how can i do that? Thanks Get user from UserManager by email. var user = UserManager.FindByEmail(email); Then use SignInManager's PasswordSignInAsync with user's Username var result = await SignInManager .PasswordSignInAsync(user.UserName,password,isPersistent,shouldLockout); Or inside your SignInManager add this

ASP MVC Build Throwing Warning For ApplicationUser Roles Navigation Property?

喜欢而已 提交于 2019-11-28 06:15:59
问题 I have the following ApplicationUser Model: public class ApplicationUser : IdentityUser { public string FirstName { get; set; } public string LastName { get; set; } public virtual ICollection<ApplicationRole> Roles { get; set; } public bool HasRole(string _role) { return Roles.Any(r => r.Name == _role); } public bool HasPermission(string _permission) { return Roles.Any(r => r.Permissions .Any(p => p.Name == _permission)); } } But when I run a build I get the following warning message: