473,387 Members | 1,572 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Custom role provider not working

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
7 3907
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: techsupport | last post by:
I have some experience with .NET Remoting, as well as ASP.NET 2.0, and have been wanting to remote a custom membership and profile provider. I want to take advantage of the new controls in ASP.NET...
1
by: CK | last post by:
Does anyone have any experience with this? We have an exisitng sql database with user and role info. I need to write a custom role provider to use this data. Does anyone have any examples of this...
1
by: Jakob Lithner | last post by:
When I started a new ASP project I was eager to use the login facilities offered in Framework 2.0/VS 2005. I wanted: - A custom principal that could hold my integer UserID from the database -...
0
by: Alex Brown | last post by:
Is it a problem to attach Non-static site map providers under one that inherits from StaticSiteMapProvider ? We are implementing a custom site map provider for a website that is being converted...
5
by: Alias | last post by:
Hi - I'm trying to implement a custom RoleProvider based on the SqlRoleProvider. I keep receiving a an error that it can't load type 'MyRoleTest.MyRoleProvider' when trying to load my...
8
by: Tomasz | last post by:
Hello Developers! I have an interesting problem using my custom MembershipProvider, RoleProvider and Forms Authentication. Both MembershipProvider and RoleProvider require session state, where...
1
by: =?Utf-8?B?YW5vbnltb3Vz?= | last post by:
I'm working on a Web Application where we control access to our Web Pages by using Roles. We assign which roles can view which web pages in our Web.sitemap file. Due the nature of our Application...
4
by: alexandis | last post by:
We have tables of logins (users), that differs much from standard microsoft structure - we don't use control question/answer, date fields, etc. But instead we have several additional fields. I...
6
by: Jonathan Wood | last post by:
Although this will be a challenge at my level of ASP.NET knowledge, I'm thinking I should implement my own membership provider class. Looking over the methods I must implement, a number of...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.