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

  • SEARCH
  • Home
  • 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 338953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:28:39+00:00 2026-05-12T10:28:39+00:00

Basically I’m writing my own version of a ‘RoleProvider’ and ‘AuthorizeAttribute’. I’ve got an

  • 0

Basically I’m writing my own version of a ‘RoleProvider’ and ‘AuthorizeAttribute’. I’ve got an Enum (as a bit field) with a list of all possible roles:

namespace myProject.Global
{
    [Flags]
    enum Roles
    {
        Viewer = 1,
        User = 2,
        Admin = 4,
        Superadmin = 8
    }
}

My AuthorizeAttribute works similarly to the existing one. In my logic, I loop through each ‘Authorized’ role and check to see if the user belongs to it. _rolesSplit is an array of the roles provided in the AuthorizeAttribute for a particular action. httpContext.Session[“Roles”] is an integer representing the user’s roles.

 foreach (string roleName in _rolesSplit)
{
    if ((httpContext.Session["Roles"] & myProject.Global.Roles[roleName]) == myProject.Global.Roles[roleName]) return true;
}

return false;

This is the part I can’t get working: APICText.Global.Roles[roleName]. I’m new to .NET development so I’m not sure how to make this work. I basically need to pass something the role name and get the associated value back. How do I do this?

  • 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. Editorial Team
    Editorial Team
    2026-05-12T10:28:39+00:00Added an answer on May 12, 2026 at 10:28 am

    What you need is Enum.Parse.

    Try something like this…

    foreach (string roleName in _rolesSplit)
    {
        if (httpContext.Session["Roles"] & (Roles)Enum.Parse(typeof(Roles), roleName) == (Roles)Enum.Parse(typeof(Roles), roleName)) return true;
    }
    

    or this…

    foreach (string roleName in _rolesSplit)
    {
        Roles role = (Roles)Enum.Parse(typeof(Roles), roleName);
        if (httpContext.Session["Roles"] & role == role) return true;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically I am writing a simple bit of code to increment every one second
Basically I have three pages. -A page with all possible search results for example:
Basically, something better than this: <input type=file name=myfile size=50> First of all, the browse
Basically I'm going to go a bit broad here and ask a few questions
Basically what I am doing is giving a user a list of terms via
Basically, what is needed to perform multisampled deferred shading. To expand a bit: I'm
Basically I have converted a tab delimited txt file into a list containing a
Basically I wanna know if all the types in a particular namespace implements a
Basically I have a field in my table called sex, and it's a boolean.
Basically, I've seen this used all to often: public event MyEventHandler MyEvent; private void

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.