We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Using Asp.Net Configuration Tool On Production Server

npl77
npl77 asked
on
Medium Priority
588 Views
Last Modified: 2017-08-30
I am not able to execute this line of code on my web host....
 Roles.AddUserToRole(username, "User");

The reason is the "User" role has to be added in the Asp.Net configuration tool. How can I access the asp.net configuration tool on a proiduction server. I dont have physical access to the server I am using lunarpages as a webhost. Or is there a way to manually add a role(whatever the asp configuration tool is doing when you add roles). I have tried to simply add data to the aspnet_Roles table but it doesnt  work because I think someowhere the configuration tool is generating its own "roleid" or I need to do something else the aspnet configuration tool is doing behind the scenes. Thanks in advance
Comment
Watch Question

Top Expert 2013

Commented:
Roles.AddUserToRole(username, "User");
should do the work...
Are you getting any errors? if so what?

AspNet Configuration will work on local machine only.

Author

Commented:
The exception I am getting on the live server is "Unable to connect to SQL Server Database". The thing is I am accessing the database in previous and subsequent lines of code no problem. So I tested this scenerio on my local machine. If I dont add roles in the conguration tool AddUserToRole breaks on the local machine even though there are roles with roleids in the aspnet_Roles table. So on my local machine I have a case where the config tool shows no roles and there are roles in the table this scenerio wont let AddRoleToUser work. Now if I add a role to the config tool then AddRoleToUser works fine. So this tells me aspnet configuration tool is doing something more than simply adding a role to the aspnet_Roles table.
Top Expert 2013

Commented:
Looks the connectionString for your Role Provider is not pointing to right DB.
Can you share your membership and role provider settings from your web.config here.

Author

Commented:
I dont know if I have roleprovider settings this is what i got in web.config...
<membership>
			<providers>
				<remove name="AspNetSqlMembershipProvider"/>
				<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider,&#xA;System.Web,&#xA;Version=2.0.0.0, Culture=neutral,&#xA;PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="ASPNETDBConnection" enablePasswordRetrieval="false" enablePasswordReset="true" applicationName="/" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" passwordAttemptWindow="10" minRequiredPasswordLength="5" minRequiredNonalphanumericCharacters="0" passwordStrengthRegularExpression="" requiresQuestionAndAnswer="false"/>
			</providers>
		</membership>
	<roleManager enabled="true"/>

Open in new window

Author

Commented:
How do I setup role provider settings. Maybe this is my problem. But how can it be working on my local machine if I dont have the settings in my web config?
Top Expert 2013
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview

Author

Commented:
Then just manually add the roles I want  to use to the aspnet_roles table?
Top Expert 2013

Commented:
No if you add roles manually ..there is no guarantee that it will work...
You should add roles using Roles API i.e.
Roles.AddUserToRole(username, "User");

Author

Commented:
Thanks again sami that fixed it! You have been a big help to me. Could you take a look a my ReportViewer problem doesnt seem like anyone can figure this one out.

Author

Commented:
What I meant by adding roles is adding the actual role like "User", "Administrator" etc...
Top Expert 2013

Commented:
Not sure if you figured it out but...here is how you would create role
if(!Roles.RoleExists("User"))
        { Roles.CreateRole("User");
        }
For the ReportViewer problem...I don't have much exposure but let me see if have something to say on that.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.