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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:45:50+00:00 2026-05-23T09:45:50+00:00

I recently starded developing for MVC 3 but have experience in both C# and

  • 0

I recently starded developing for MVC 3 but have experience in both C# and ASP.NET since earlier. So i’ll start with what i’m trying to accomplish. I’ve developed a small site for hosting articles. I’ve implemented SQLServer based membership managament to the site. Now i want to create a credentials system that restricts and allows the right users to create, delete and update articles. There is one simple solution to this and that is to do it like this:

[Authorize(Roles="Admin")]
    public ActionResult UpdateArticle(ArticleModel model, int articleid)
    {
        return View();
    }

Now this is really simple. I simply say that only members that are in the role “Admin” are allowed to update an article. But that’s just to static. So i created a credentials table in my database that in the end tells me that “Article 5 can be edited by roles 1,2,3 & 4 and by users A, b & C”. So far so good. But how would i implement that with the Authorize solution?

I would like to do something like this:

[Authorize(getAuthorizedusers("update",this.articleid))]

where getAuthorizedusers returns which users and roles are authorized to update the article with the articleid that was passed to it.

So I have (at least) two problems here:
-Getting the Authorize method to accept multiple users and roles.
-Passing the supplied articleid, that was sent to the UpdateArticle method, to the getAuthorizedusers method.

  • 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-23T09:45:50+00:00Added an answer on May 23, 2026 at 9:45 am

    You can create your own custom attribute that inherits from AuthorizeAttribute and override the OnAuthorize method to do what you need.

    This should get you started:

    public class ArticleAuthorizeAttribute : AuthorizeAttribute
    {
        public enum ArticleAction
        { 
            Read,
            Create,
            Update,
            Delete
        }
    
        public ArticleAction Action { get; set; }
    
        public override void OnAuthorization(AuthorizationContext filterContext)
        {
            base.OnAuthorization(filterContext);
    
            //do custom authorizization using Action and getting ArticleID 
            //from filterContext.HttpContext.Request.QueryString or
            //filterContext.HttpContext.Request.Form
        }
    }
    

    The usage would look like this:

    [ArticleAuthorize(Action=ArticleAuthorizeAttribute.ArticleAction.Update)]
    

    Edit: After looking into this a bit more, it looks like you can’t pass this.articleID in to the attribute. However, you do have access to the parameters from filterContext.HttpContext.Request through the QueryString property or the Form property, depending on how you are passing the values. I have updated the code sample appropriately.

    A more complete example can be found here

    To check for authorization using user role and user list you would do something like this:

            var allowedUsers = new List<string>();
            //populate allowedUsers from DB
    
            If (User.IsInRole("Update") || allowedUsers.Contains(User.Identity.Name))
            {
                //authorized
            }
    

    Alternatively, you can do both checks against the DB directly in a single method to keep from making two calls.

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

Sidebar

Related Questions

Recently started with ASP.NET and MVC and have a few questions on working with
This is a weird problem I have started having recently. My team is developing
So we have recently started developing applications for the iPad for our company. Unfortunately
I've just recently started developing a site for iPhone using jQTouch, and have the
I have started developing a webpage and recently hired someone to write code to
I have quite a few years experience of developing PHP web applications, and have
Recently, I have started using Xcode 4 for developing iOS apps. In Xcode intellisense's
I have recently started on a project developing a window mobile/ce buisiness application. I
I'm kind of new to the whole MVC concept, since I just recently started
I recently started developing websites on wordpress. I have this problem with tinymce editor.

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.