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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:16:45+00:00 2026-06-18T00:16:45+00:00

How to enable roles in mvc?? my code is given below and i dont

  • 0

How to enable roles in mvc?? my code is given below and i dont know how to create roles and i want to add it to the databse..

[AttributeUsage(AttributeTargets.All)]
    public class UserRightAttribute : ActionFilterAttribute
    {
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            //write your user right logic
            //if user has right to do nothig otherwise redirect to error page.
            string message = "It seems You  are not authorize to view this part of the web site!!!.";
            RouteValueDictionary redirectTargetDictionary = new RouteValueDictionary();
            redirectTargetDictionary.Add("area", "");
            redirectTargetDictionary.Add("action", "SaveData");
            redirectTargetDictionary.Add("controller", "Home");
            redirectTargetDictionary.Add("customMessage", message);
            filterContext.Result = new RedirectToRouteResult(redirectTargetDictionary);
        }
    }
  • 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-06-18T00:16:47+00:00Added an answer on June 18, 2026 at 12:16 am

    First web.config add following

    <system.web>
        <roleManager enabled="true" />
        ...
    

    Adding roles is the same like ASP.NET for example

    Roles.CreateRole("RoleName");
    Roles.AddUserToRole("userName", "RoleName");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to enable caching for all Anonymous users of my site. But for
How can I Enable/Disable Roles or Create or Manage Roles without ASP.NET Web Site
Is there a way to enable windows server 2008 roles from C# code? My
I want to enable code coverage for some unit test in my solution. After
I have the following code to enable validation work: $(document).ready(function() { $(#eventForm).validate({ rules: {
i enable hl-mode in global scope with the following code. (global-hl-line-mode t) to turn
I like to enable users to choose their role on register in asp.net mvc
I am using instructions provided at http://code.google.com/appengine/articles/openid.html to enable Federated Authentication in App Engine.
I'm trying to create a new MVC 4 internet site using the internet template
Has anybody come across occurrences where MVC does not recognize roles from Windows? I

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.