Solved

Using Asp.Net Configuration Tool On Production Server

Posted on 2009-07-07
11
393 Views
Last Modified: 2012-05-07
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
0
Comment
Question by:npl77
  • 6
  • 5
11 Comments
 
LVL 41

Expert Comment

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

AspNet Configuration will work on local machine only.
0
 

Author Comment

by:npl77
ID: 24796916
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.
0
 
LVL 41

Expert Comment

by:guru_sami
ID: 24796950
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.
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

Author Comment

by:npl77
ID: 24797111
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

0
 

Author Comment

by:npl77
ID: 24797163
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?
0
 
LVL 41

Accepted Solution

by:
guru_sami earned 500 total points
ID: 24797165
You should modify your role provider like this.

Note the connectionString is ASPNETDBConnection where your roles are/to be stored.

<roleManager enabled="true">
<providers>
<clear />
<add name="AspNetSqlRoleProvider" connectionStringName="ASPNETDBConnection" applicationName="/" type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
</providers>
</roleManager>
0
 

Author Comment

by:npl77
ID: 24797222
Then just manually add the roles I want  to use to the aspnet_roles table?
0
 
LVL 41

Expert Comment

by:guru_sami
ID: 24797260
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");
0
 

Author Closing Comment

by:npl77
ID: 31600705
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.
0
 

Author Comment

by:npl77
ID: 24797360
What I meant by adding roles is adding the actual role like "User", "Administrator" etc...
0
 
LVL 41

Expert Comment

by:guru_sami
ID: 24798034
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.
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question