PC Review


Reply
Thread Tools Rate Thread

Custom role provider not working

 
 
Tom Van den Brandt
Guest
Posts: n/a
 
      31st May 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
 
      31st May 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
 
      4th Jun 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;database=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
 
      4th Jun 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;database=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
 
      5th Jun 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
 
      5th Jun 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.Identity, 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
 
      5th Jun 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
 
      5th Jun 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
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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
Passing UserGUID to the Custom Role Provider Temoc Microsoft ASP .NET 1 22nd Jun 2010 02:05 AM
Tracing problems with Custom Role Provider James Crosswell Microsoft ASP .NET 2 9th Nov 2007 01:50 PM
Authorization with custom role provider =?Utf-8?B?QXJuZQ==?= Microsoft ASP .NET 1 17th Aug 2007 02:12 AM
Custom Role Provider CK Microsoft ASP .NET 1 25th Jul 2006 08:24 PM
debug a custom membership and role provider? =?Utf-8?B?QmVuIFIu?= Microsoft ASP .NET 5 17th May 2006 01:04 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:38 AM.