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 7536159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:30:02+00:00 2026-05-30T06:30:02+00:00

I’m having a hard time figuring out how to work with the two string

  • 0

I’m having a hard time figuring out how to work with the two string arrays passed into AddUsersToRoles.

Here’s what I think I need to do:

  • First get the int UserID for the string[] usernames.
  • Then get the int RoleID for string[] roles.
  • Concat the two arrays together.
  • Save the data to UserRole (a database that contains 3 columns: UserRoleID, UserID, RoleID).

Here’s what it looks like:

//override and implement a custom 'adduserstoroles' from the abstract method in RoleProvider

    public override void AddUsersToRoles(string[] usernames, string[] roleNames)
    {
        int[] userid;

        foreach(var username in usernames)
        {
            User user = AuthRepository.GetUser(username);
            //Error 1: An object reference is required for the non-static field, method, or property 'CustomAuth.AuthRepository.GetUser(string)'

            userid = user.ID;
            //Error 2: Cannot implicitly convert type 'int' to 'int[]'

        }

        int[] roleid;

        foreach(var rolename in roleNames)
        {
            Role role = db.Roles.Where(r => r.RoleName == rolename).SingleOrDefault();

            roleid = role.RoleID;
            //Error 3: Cannot implicitly convert type 'int' to 'int[]'

        }

        var userroles = userid.Concat(roleid).ToArray(); 

        foreach(var userrole in userroles)
        {
            UserRole userRole = new UserRole();
            db.UserRoles.Add(userRole);

        }

    }

Now, I don’t know if I’m going off the deep end on this. I’ve searched around for examples of how others have handled this type of thing but I can’t find any answers.

  • 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-30T06:30:04+00:00Added an answer on May 30, 2026 at 6:30 am

    for error 2 and 3, you’re trying to assign a plain old int to an array of ints, which doesn’t make any sense. You probably just want to make userid and roleid List’s of ints

    List<int> roleid = new List<int>();
    

    Then in the foreach loops, you can just

    roleid.Add(user.ID);
    

    and

    for error 1, it looks like AuthRepository isn’t a static class, so you’d need to create an instance of it before using it.

    foreach (var username in usernames) 
    {
        AuthRepository repository = new AuthRepository();
        repository.GetUser(username);
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
Specifically, suppose I start with the string string =hello \'i am \' me And
I have a French site that I want to parse, but am running into

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.