Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 103507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:08:05+00:00 2026-05-11T01:08:05+00:00

In a custom role provider (inheriting from RoleProvider) in .NET 2.0, the IsUserInRole method

  • 0

In a custom role provider (inheriting from RoleProvider) in .NET 2.0, the IsUserInRole method has been hard-coded to always return true:

public override bool IsUserInRole(string username, string roleName) { return true; } 

In an ASP.NET application configured to use this role provider, the following code returns true (as expected):

Roles.IsUserInRole('any username', 'any rolename'); // results in true 

However, the following code returns false:

Roles.IsUserInRole('any rolename'); // results in false 

Note that User.IsInRole(‘any rolename’) is also returning false.

  1. Is this the expected behavior?
  2. Is it incorrect to assume that the overload that only takes a role name would still be invoking the overridden IsUserInRole?

Update: Note that there doesn’t seem to be an override available for the version that takes a single string, which has led to my assumption in #2.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T01:08:06+00:00Added an answer on May 11, 2026 at 1:08 am

    I looked at Roles.IsUserInRole(string rolename) in .net reflector, and it resolves to the following:

    public static bool IsUserInRole(string roleName) {     return IsUserInRole(GetCurrentUserName(), roleName); } 

    I would take a look at your current user. Here’s why:

    private static string GetCurrentUserName() {     IPrincipal currentUser = GetCurrentUser();     if ((currentUser != null) && (currentUser.Identity != null))     {         return currentUser.Identity.Name;     }     return string.Empty; } 

    I would be willing to bet this is returning an empty string because you either don’t have a Current User, or its name is an empty string or null.

    In the IsUserInRole(string username, string roleName) method, there is the following block of code right near the beginning:

       if (username.Length < 1)    {        return false;    } 

    If your GetCurrentUserName() doesn’t return anything meaningful, then it will return false before it calls your overridden method.

    Moral to take away from this: Reflector is a great tool 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 73k
  • Answers 73k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer I know it's not C# .NET but ffmpeg is a… May 11, 2026 at 1:59 pm
  • added an answer You can use dataRow.IsNull('Amount') or Convert.IsDBNull(dataRow['Amount']) or (dataRow['Amount'] as Decimal)… May 11, 2026 at 1:59 pm
  • added an answer Break it into steps: Go through your sortedValuesList and build… May 11, 2026 at 1:59 pm

Related Questions

In a custom module for drupal 4.7 I hacked together a node object and
I have a custom validation function in JavaScript in a user control on a
I have a custom aspx page loaded in a IFrame in one of the
In a FLEX app, I am trying to re-dispatch a custom event. I.e. component1
Hello i have a website in Sharepoint that is using variations. I have for
I have created my own Role Provider because I found the one that ASP.Net
I'm working on a project where I need the following. WCF service on the
We have an intranet asp.net web application which uses the OOTB ASP.net membership and

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.