?
Solved

Using Asp.Net Configuration Tool On Production Server

Posted on 2009-07-07
11
Medium Priority
?
400 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 2000 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

777 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