 |
| ASP.NET 4 General Discussion For ASP.NET 4 discussions not relating to a specific Wrox book |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 4 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

June 27th, 2011, 08:14 AM
|
|
Registered User
|
|
Join Date: Jun 2011
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
Custom Role Provider issue
Hello everybody,
I am a new user to both programming and this forum and I was wondering if anybody could help me with a little issue I am having concerning custom role providers.
After looking up many tutorials on the subject, my role manager settings in the web.config appear to be configured correctly. However when I add a new role programmatically it does not appear in my custom database under the table "aspnet_Roles", though it appears in the ASP.Net Website Administration Tool.
This is the main tutorial that I was using http://www.asp.net/security/tutorial...aging-roles-vb
The code for my role manager settings appear below:
Code:
<connectionStrings>
<add name="SecurityTutorialsConnectionString"
connectionString="Data Source=TGM830\SQLEXPRESS;AttachDbFilename=c:\users\david varley\documents\visual studio 2010\Projects\AspnetWebsite\AspnetWebsite\App_Data\SECURITYTUTORIALS.MDF;Integrated Security=True;User Instance=True"
providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.web>
<roleManager defaultProvider="SecurityTutorialsSqlRoleProvider" enabled="true" cacheRolesInCookie="true">
<providers>
<clear />
<remove name ="AspNetSqlRoleProvider"/>
<add name="SecurityTutorialsSqlRoleProvider"
type="System.Web.Security.SqlRoleProvider"
connectionString="Data Source=TGM830\SQLEXPRESS;AttachDbFilename=c:\users\david varley\documents\visual studio 2010\Projects\AspnetWebsite\AspnetWebsite\App_Data\SECURITYTUTORIALS.MDF;Integrated Security=True;User Instance=True"
applicationName="SecurityTutorials"
connectionStringName="SecurityTutorialsConnectionString"/>
</providers>
</roleManager>
The connection string shown here works for entering new users onto the site, so I figured the same would be the case for creating new roles.
If any more information is needed I will happily supply it.
If anybody could point me in the right direction it would be much appreciated.
Thanks, Dj
|
|

June 27th, 2011, 10:33 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
Try the following:
1. Move your site out of the My Documents folder and into a folder such as c:\Sites. Then update the connection string accordingly. You're less likely to run into security and configuration issues.
2. Remove the connectionString from the role element. The provider looks at the connectionStringName which in turn provides the connection string.
Hope this helps,
Imar
|
|

June 27th, 2011, 10:34 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
BTW, can you post the code you have to create roles?
Imar
|
|

June 27th, 2011, 10:40 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
One more thing (that will teach me to better read a post before I start answering), this:
Quote:
|
However when I add a new role programmatically it does not appear in my custom database under the table "aspnet_Roles", though it appears in the ASP.Net Website Administration Tool.
|
seems to suggest multiple databases are in play; one that the WSAT is looking at, and one you are looking at. Are you sure the correct settings are in place everywhere?
Imar
|
|

June 27th, 2011, 10:56 AM
|
|
Registered User
|
|
Join Date: Jun 2011
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
Hi Imar,
Thank you for your reply.
I have moved my site across to C:/
I only have one database that I know of and that is the one specified in the connection string "SecurityTutorials.mdf". I registered it using the aspnet_regsql.exe tool and attached it using Sql Server Management Studio.
Below is my code for creating a new role,
Code:
Protected Sub CreateRoleButton_Click(ByVal sender As Object, ByVal e As EventArgs) Handles CreateRoleButton.Click
Dim newRoleName As String = RoleName.Text.Trim()
If Not Roles.RoleExists(newRoleName) Then
' Create the role
Roles.CreateRole(newRoleName)
DisplayRolesInGrid()
End If
RoleName.Text = String.Empty
End Sub
Thanks, Dj
|
|

June 27th, 2011, 11:10 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
If you attached the database to sql server, you shouldn't specify the path in the connection string, but instead use Initial Catalog. For examples of proper connection strings, take a look at www.connectionstrings.com
Cheers,
Imar
|
|
The Following User Says Thank You to Imar For This Useful Post:
|
|
|

June 27th, 2011, 11:24 AM
|
|
Registered User
|
|
Join Date: Jun 2011
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
Hello Imar,
Thanks to your help the problem is now solved and my roles are now appearing in my database.
Highest Regards, Dj
(I'll probably be back sooner or later with another future issue) 
|
|

June 27th, 2011, 01:38 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
For the benefit of the archive of this forum (for future readers with a similar issue), would you mind sharing *how* you fixed the issue?
Cheers,
Imar
|
|
 |