I had a web app where I have used ASP.NET Identity, It was working fine on my machine but when I published it on the hosting server the Role system partially stopped working.
There was a portion of code where I used to manage Edit roles, here is the code below
string[] roles = { "Company", "User" };
//Assign Role to user Here
var roleStore = new RoleStore<IdentityRole>(context);
var roleManager = new RoleManager<IdentityRole>(roleStore);
var userStore = new UserStore<ApplicationUser>(context);
var userManager = new UserManager<ApplicationUser>(userStore);
Roles.RemoveUserFromRoles(username, roles);
this.UserManager.RemoveFromRoles(company.Id, roles);
if (company.Approved)
{
this.UserManager.AddToRole(company.Id, "Company");
}
else
{
this.UserManager.AddToRole(company.Id, "User");
}
NOTE: company.Id is the userId so it is fine.
Again, It was working fine on my machine, when I published it, it stopped working and doesn't show any errors and it does the rest of the code below this portion.
I guess it maybe something in the connection string in web.config but not sure what is it.
I hope I can find a solution as I have been searching for a while couldn't find anything.
UPDATE 1: I have found that it is only working on the localhost but not on server, when I tried connecting to the hosting server database from VS from my machine and debugged, I found that it works fine but when testing using the site link it doesn't work..
UPDATE 2: I have finally knew where is the error from, it is from setting the applicationName here in roleManager, how to know my applicationName when hosted?