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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:19:58+00:00 2026-05-28T04:19:58+00:00

i am creating a MVC3 application where the user can be either an Admin

  • 0

i am creating a MVC3 application where the user can be either an Admin or a Data Entry, so i need to make use of the Role in user authentication that MVC offers. So in my Register Form I Have added

                    <%=  
                           Html.DropDownList("RoleName", new SelectListItem[]{ 
                           new SelectListItem{ Text= "Admin", Value="admin"},
                           new SelectListItem{ Text= "Data Entry", Value="data"}
                    }) %>

And i modified the register controller as follows:

if (createStatus == MembershipCreateStatus.Success)
                {
                    Roles.AddUserToRole(model.UserName, "RoleName");
                    FormsAuthentication.SetAuthCookie(model.UserName, false /* createPersistentCookie */);
                    return RedirectToAction("Index", "Home");
                }

Now when i register i get the following error:
The role ” was not found.

Thank you …

  • 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-28T04:19:59+00:00Added an answer on May 28, 2026 at 4:19 am

    Take a look at the definition for Roles.AddUserToRole() method here. You are hardcoding “RoleName” for the second parameter which is supposed the role to add the user to.

    What you want to do is retrieve the selected value from your DropDownList and use that string in your Roles.AddUserToRole() method call.

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

Sidebar

Related Questions

I'm creating user control in MVC3 application. My view model looks like that: public
I'm currently creating an application using the MVC3 framework. I understand how to use
I'm creating an AppHarbor MVC3 application and want to use the standard membership provider
When creating a web application, and lets say you have a User object denoting
Im creating a custom field in MVC3 (C#) that I would like to access
I have an ASP.NET MVC3 application in which I am creating multiple areas, is
I am creating a new web application using ASP.NET MVC3 Razor and HTML 5.
I'm looking at creating my first ASP.NET MVC application using MVC3. The project template
Currently, I am creating an application using ASP.NET MVC3 and MySQL and when I
I have a asp.net MVC3 Application with two users Admin and General.Cookies is saved

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.