Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Custom role provider not working

Reply
Thread Tools

Custom role provider not working

 
 
Tom Van den Brandt
Guest
Posts: n/a
 
      05-31-2007
Hi all!

I'm trying to implement a custom roleprovider in asp.net. The new
roleprovider works fine when I access it programmaticaly. However, it
doesn't seem to work with the standard controls. More specifically, I
have a loginview with rolegroups and the parts of the site that should
be viewable for a certain role, do not show up. Did I forget something?

Regards,

Tom
 
Reply With Quote
 
 
 
 
=?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
Guest
Posts: n/a
 
      05-31-2007
Do you have this set up properly in your web.config entries? Do you have a
"remove name=XXx" at the top of the section to remove the default roles
provider before you add your entry for your custom one?
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net




"Tom Van den Brandt" wrote:

> Hi all!
>
> I'm trying to implement a custom roleprovider in asp.net. The new
> roleprovider works fine when I access it programmaticaly. However, it
> doesn't seem to work with the standard controls. More specifically, I
> have a loginview with rolegroups and the parts of the site that should
> be viewable for a certain role, do not show up. Did I forget something?
>
> Regards,
>
> Tom
>

 
Reply With Quote
 
 
 
 
Tom Van den Brandt
Guest
Posts: n/a
 
      06-04-2007
Yes, I do...

Here's a section from my web.config:


<roleManager defaultProvider="CustomRoleProvider"
enabled="true"
>

<providers>
<clear />
<remove name="AspNetSqlRoleProvider"/>
<add
name="CustomRoleProvider"
type="CustomRoleProvider"
connectionString="server=rakels10.synstar.be;datab ase=websupporttables;user
id=xxxxx password=xxxxx;"
applicationName="/"
writeExceptionsToEventLog="false" />
</providers>
</roleManager>


I don't get it, I have a testpage where I try some of the methods from
my custom role provider and this works... e.g.:

Dim provider As RoleProvider = New CustomRoleProvider
Dim roles() As String = provider.FindUsersInRole("user", "%")
...


Peter Bromberg [C# MVP] schreef:
> Do you have this set up properly in your web.config entries? Do you have a
> "remove name=XXx" at the top of the section to remove the default roles
> provider before you add your entry for your custom one?
> Peter
>

 
Reply With Quote
 
=?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
Guest
Posts: n/a
 
      06-04-2007
Then I'd suggest running this in debug mode with the source code project for
your role provider in the solution. Set breakpoints at the appropriate places
and trace through your code to find out what may be wrong.

If your breakpoints don't get hit, that means your configuration setup is
wrong.
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net




"Tom Van den Brandt" wrote:

> Yes, I do...
>
> Here's a section from my web.config:
>
>
> <roleManager defaultProvider="CustomRoleProvider"
> enabled="true"
> >

> <providers>
> <clear />
> <remove name="AspNetSqlRoleProvider"/>
> <add
> name="CustomRoleProvider"
> type="CustomRoleProvider"
> connectionString="server=rakels10.synstar.be;datab ase=websupporttables;user
> id=xxxxx password=xxxxx;"
> applicationName="/"
> writeExceptionsToEventLog="false" />
> </providers>
> </roleManager>
>
>
> I don't get it, I have a testpage where I try some of the methods from
> my custom role provider and this works... e.g.:
>
> Dim provider As RoleProvider = New CustomRoleProvider
> Dim roles() As String = provider.FindUsersInRole("user", "%")
> ...
>
>
> Peter Bromberg [C# MVP] schreef:
> > Do you have this set up properly in your web.config entries? Do you have a
> > "remove name=XXx" at the top of the section to remove the default roles
> > provider before you add your entry for your custom one?
> > Peter
> >

>

 
Reply With Quote
 
Tom Van den Brandt
Guest
Posts: n/a
 
      06-05-2007
Thanks for the helping hand...

I've tried you're suggestion. I've put some breakpoints in the role
provider code and they do get hit. So no configuration error I guess...
It looks to me that the role provider is working fine, but the roles are
not added to the user data or something (because the content defined in
rolegroups is not shown)...


Peter Bromberg [C# MVP] schreef:
> Then I'd suggest running this in debug mode with the source code project for
> your role provider in the solution. Set breakpoints at the appropriate places
> and trace through your code to find out what may be wrong.
>
> If your breakpoints don't get hit, that means your configuration setup is
> wrong.
> Peter
>

 
Reply With Quote
 
Tom Van den Brandt
Guest
Posts: n/a
 
      06-05-2007
Some extra info:

When I programatically 'use' the roleprovider everything works fine, e.g.:

Dim provider As RoleProvider = New CustomRoleProvider
Dim roles() As String = provider.GetRolesForUser("Tom")
Dim roleexists As Boolean = provider.IsUserInRole("Tom", "user")

This all returns the correct results.

But when I use:
System.Web.Security.Roles.IsUserInRole("Tom", "user")

I get incorrect results.

I guess some binding or something needs to be done after authentication.
I've found an article on putting some extra code in a global asax file
but that doesn't seem to work either. This is the code I've tried:

Protected Sub Application_AuthenticateRequest(ByVal sender As Object,
ByVal e As System.EventArgs)
Try
If Request.IsAuthenticated Then
Dim roleprovider As RoleProvider = New CustomRoleProvider
Dim roles As String() =
roleprovider.GetRolesForUser(User.Identity.Name)
HttpContext.Current.User = New
System.Security.Principal.GenericPrincipal(User.Id entity, roles)
End If
Catch ex As Exception
Console.Write(ex.ToString)
End Try
End Sub


Peter Bromberg [C# MVP] schreef:
> Then I'd suggest running this in debug mode with the source code project for
> your role provider in the solution. Set breakpoints at the appropriate places
> and trace through your code to find out what may be wrong.
>
> If your breakpoints don't get hit, that means your configuration setup is
> wrong.
> Peter
>

 
Reply With Quote
 
Tom Van den Brandt
Guest
Posts: n/a
 
      06-05-2007
Problem solved...

While debugging I saw that my role names had trailing spaces in them (in
the database) and because 'user' <> 'user ' the role groups were not
working. How this spaces got in the db, no idea... I've added a trim
function to remove unnecessary spaces and everything works fine now...

Peter Bromberg [C# MVP] schreef:
> Then I'd suggest running this in debug mode with the source code project for
> your role provider in the solution. Set breakpoints at the appropriate places
> and trace through your code to find out what may be wrong.
>
> If your breakpoints don't get hit, that means your configuration setup is
> wrong.
> Peter
>

 
Reply With Quote
 
=?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
Guest
Posts: n/a
 
      06-05-2007
See that? Knew you could do it!
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net




"Tom Van den Brandt" wrote:

> Problem solved...
>
> While debugging I saw that my role names had trailing spaces in them (in
> the database) and because 'user' <> 'user ' the role groups were not
> working. How this spaces got in the db, no idea... I've added a trim
> function to remove unnecessary spaces and everything works fine now...
>
> Peter Bromberg [C# MVP] schreef:
> > Then I'd suggest running this in debug mode with the source code project for
> > your role provider in the solution. Set breakpoints at the appropriate places
> > and trace through your code to find out what may be wrong.
> >
> > If your breakpoints don't get hit, that means your configuration setup is
> > wrong.
> > Peter
> >

>

 
Reply With Quote
 
rwiethorn rwiethorn is offline
Junior Member
Join Date: Jun 2007
Location: Cincinnati
Posts: 1
 
      06-11-2007
Tom,
I too have to implement my own RoleProvider. Can you help me get started. I'm not sure where I put the part to create the RoleClass, and how its 'wired up' to the LoginControls.

My project/webiste is currently working using the Default Database Schema with the SQLMemebership and SQLRoleProviders, but due to scope change I need to change the datasource of my RoleTables.

For Starters I made my own class called: clsMyRoleProvider.vb, and copied the code I found here (http://msdn2.microsoft.com/en-us/lib...4k(vs.80).aspx)

From your above sample I'll modify my Webconfig.

Question: Do you have them sign in? and get the username: strUser= me.lblUser.txt?

then 'somehow' make a trip to the server to get the role out from the Database.

When you make the trip to the DB and return a role value (ie Admin, Author, Browser) how do you connect or inform the LoginView Control what to render?

As I said before, I've it working with the SQLRole Providers, so I'm not sure if I need to set some properties on the control to look at MyRoleProvider.

All help is appreciated.
Thanks
rwiethorn
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Authorization with custom role provider =?Utf-8?B?QXJuZQ==?= ASP .Net 1 08-17-2007 01:12 AM
Membership or Role Provider // Provider Model // Factories .. How does MS do it? sloan ASP .Net 1 07-03-2007 08:17 PM
Custom Role Provider give "can't load type error" Alias ASP .Net 5 02-18-2007 11:09 PM
Custom Role Provider CK ASP .Net 1 07-25-2006 07:24 PM
debug a custom membership and role provider? =?Utf-8?B?QmVuIFIu?= ASP .Net 5 05-17-2006 12:04 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57