By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,984 Members | 1,386 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,984 IT Pros & Developers. It's quick & easy.

Custom role provider not working

P: n/a
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
May 31 '07 #1
Share this Question
Share on Google+
7 Replies


P: n/a
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
May 31 '07 #2

P: n/a
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
Jun 4 '07 #3

P: n/a
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
Jun 4 '07 #4

P: n/a
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
Jun 5 '07 #5

P: n/a
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
Jun 5 '07 #6

P: n/a
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
Jun 5 '07 #7

P: n/a
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
Jun 5 '07 #8

This discussion thread is closed

Replies have been disabled for this discussion.