Click here to Skip to main content
15,920,053 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am getting the following error in asp.net application
The user 'a' is already not in role 'Provisional'

the relevant portion of code where I get this error is (line 29 below)

Line 27: if(Roles.IsUserInRole("Provisional"))
Line 28: {
Line 29: Roles.RemoveUserFromRole(username, "Provisional");
Line 30: Roles.AddUserToRole(username, "Provisional1");
Line 31: Response.Redirect("~/Profiles/ProfileBasics.aspx?");
Line 32 }

Since to user is not in role Provisional, this part of code should have been overlooked by server.

I want to perform this code only if User is in role Provisional, else other code works. But I invariably get this error when User is in role Provisional.

Kindly help me overcome this error.

I am new to asp.net and I am using C#

Many thanks for help
Posted
Comments
gettgotcha 15-Jan-14 15:40pm    
Did you debug the code and checked whats the value you are getting for the "Role"? What is the error stating?

Without the rest of your code it's impossible to give you the exact answer, but...
Your if test checks if the current user is in a role, and if he is continues with the Remove: Roles.IsUserInRole[^]
The remove uses the username that you pass to the method: Roles.RemoveUserFromRole[^], not the current user.

So, if the current logged in user (i.e. you) is in the Provisional role, then you will try to remove whoever has the username in your username variable from Provisional.

I'm guessing that the current logged in user is not the same as the user in username...use the debugger and check!
 
Share this answer
 
As OriginalGriff explained in the solution ,
Roles.IsUserInRole("Provisional") => checks with current logged in User
http://msdn.microsoft.com/en-us/library/4z6b5d42(v=vs.110).aspx

Roles.IsUserInRole("UserName", "Provisional")=>checks with the specified user is in that Role.

http://msdn.microsoft.com/en-us/library/bz1zy88e(v=vs.110).aspx

Suggestion is ,if trying to remove a user who is not the current logged in then have to use Roles.IsUserInRole("UserName", "Provisional") in your if condition check or else the condition will be true and will try to remove a user who is not having the role.
 
Share this answer
 
Comments
Member 10235977 19-Jan-14 5:14am    
Many thanks friends
I have figured out that there is nothing wrong with my code. The problem is with the manner in which the users are using the site.
The code requires some time to execute as it has lot of calculations and the users do not have patience to wait. They click stop button or back button when the code is half executed. I find that some users have clicked the submit button again within 3 seconds, apparently by using back button / stop button in the menu bar. I also suspect that some users are doing it deliberately, as in a couple of cases the submit button has been pressed second time after less than one second.
I have also given the wait message but it has not affected some of the users. I have been able to identify the IP address of such users, as my code records the IP address on page load itself.
If you could kindly suggest how to deal with such users, who do not have patience or who prefer to do this kind of act.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900