Wrox Programmer Forums
|
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
 
Old June 27th, 2011, 08:14 AM
Registered User
 
Join Date: Jun 2011
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
Default 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
 
Old June 27th, 2011, 10:33 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old June 27th, 2011, 10:34 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

BTW, can you post the code you have to create roles?

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old June 27th, 2011, 10:40 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old June 27th, 2011, 10:56 AM
Registered User
 
Join Date: Jun 2011
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
Default

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
 
Old June 27th, 2011, 11:10 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
The Following User Says Thank You to Imar For This Useful Post:
Djvarley (June 27th, 2011)
 
Old June 27th, 2011, 11:24 AM
Registered User
 
Join Date: Jun 2011
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
Default

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)
 
Old June 27th, 2011, 01:38 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom Membership Provider Scott663 BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 4 August 1st, 2008 05:16 PM
Custom Resource Provider ssirfan29 ASP.NET 2.0 Basics 0 July 16th, 2007 08:04 AM
SQL Role Provider not instantiating jsqrd ASP.NET 2.0 Basics 0 March 26th, 2007 05:24 PM
Issue with custom membership provider cacaldo ASP.NET 2.0 Professional 1 October 7th, 2006 03:05 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.