1

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?

  • 1
    Are you developing against [Localdb](http://blog.chudinov.net/using-localdb-in-development/)? Perhaps your published environment is trying to look at Localdb and can't find it. Also, have you tried [turning on remote errors](https://stackify.com/web-config-customerrors-asp-net/) for debugging post-deployment issues? – trademark Feb 04 '19 at 21:37
  • Well, yes it was on Localdb then when I uploaded I changed the connection string to the server’s database so it automatically created the tables there, I am not sure if it is the correct way to make it. What I am wondering it doesn’t throw any errors so I don’t know where is the problem from – Ahmed Khaled Feb 05 '19 at 04:53
  • Have you tried turning on remote errors (link in previous comment)? That can be helpful. Also, if your application is generating log files on the server, you might want to dig those out. Another good technique is to run it locally but point your local instance to use the remote database. Then you can basically use the debugger to see what's wrong. Meanwhile, can you describe in more detail what the actual issue is? – trademark Feb 05 '19 at 14:09
  • Check update 1 please, I have found it works on localhost fine but doesn't work when I use site domain @trademark – Ahmed Khaled Feb 05 '19 at 15:12
  • **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? – Ahmed Khaled Feb 05 '19 at 16:15
  • Sounds like progress. Could you please add the code where applicationName is accessed, and also tell us what service you are using for hosting? – trademark Feb 05 '19 at 17:08
  • ` ` Here is the code and I am using GoDaddy as the hosting provider – Ahmed Khaled Feb 05 '19 at 17:23
  • It sounds like your question now is a little different than your original. Consider searching Google and StackOverflow for answers relevant to your issue. If you choose to ask a new question regarding your applicationName issue, please provide lots of details and all relevant code in your question. Good luck! – trademark Feb 06 '19 at 15:22

0 Answers0