Solved

Using Asp.Net Configuration Tool On Production Server

Posted on 2009-07-07
11
394 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

839 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