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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:17:41+00:00 2026-06-08T17:17:41+00:00

I want to use the following method whenever the GET or POST is called

  • 0

I want to use the following method whenever the GET or POST is called to create or edit an article page:

' userId = ID or username of the user logged in
' companyId = ID or name of the company for which the current blog is assigned
' blogId = ID or name of the blog for which the article is being written
' returnSuccessView = the view that will be returned if the user has access
' returnFailView = the view  that will be returned if the user does not have access

return View(CheckUserAccess(userId, companyId, blogId, returnSuccessView, returnFailView))

Can someone show me what this function would look like? My structure is:

Companies -> Blogs -> Articles -> Comments

I want to create permissions so only users that belong to a certain company and belong to a certain blog and have certain permissions can perform the requested task.

For instance, my user model would have an ICollection of companies to which the user can be associated with, and they can have an ICollection of blogs they can be associated with. They can also have an ICollection of permissions, such as super-user, article writer, article editor, moderator, etc.

I would create a separate model for permissions so that they can be added and removed via a UI.

The function should check whether or not the requested company, blog and permissions match that which the user is associated with (has in their ICollection).

What’s the best way to go about something like this? 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-06-08T17:17:42+00:00Added an answer on June 8, 2026 at 5:17 pm

    I would recommend you handling this with a custom [Authorize] attribute. Let’s take an example:

    public class MyAuthorizeAttribute : AuthorizeAttribute
    {
        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            var authorized = base.AuthorizeCore(httpContext);
            if (!authorized)
            {
                // The user is not even authenticated => we can't get much further
                return false;
            }
    
            // At this stage we know that there's an authneticated user
            // let's see who he is by fecthing his username
            string username = httpContext.User.Identity.Name;
    
            RouteData rd = httpContext.Request.RequestContext.RouteData;
    
            // Now, let's read the companyId and blogId parameters that he sent
            // into the request and ensure that he is not cheating on us
            string companyId = rd.Values["companyId"] as string;
            string blogId = rd.Values["blogId"] as string;
    
            if (string.IsNullOrEmpty(companyId) || string.IsNullOrEmpty(blogId))
            {
                // One of the required parameters were not supplied when the action was invoked
                // => we can't get much further
                return false;
            }
    
            return IsOwner(username, companyId, blogId);
        }
    
        private bool IsOwner(string username, string companyId, string blogId)
        {
            // TODO: you know what to do here: 
            // check with your data store or wherever you have stored this info
            throw new NotImplementedException();
        }
    }
    

    Now you could decorate your controllers/actions with this attribute:

    [MyAuthorize]
    public ActionResult Edit(string companyId, string blogId)
    {
        // if we got that far it means that the user is authorized to edit this blog post
        // and we could allow him to see the edit view
        EditViewModel model = ...
        return View(model); 
    } 
    

    And of course to ensure that the user is not trying to cheat on you on the POST action you could also decorate it with this attribute:

    [MyAuthorize]
    [HttpPost]
    public ActionResult Edit(EditViewModel model)
    {
        // if we got that far it means that the user is authorized to edit this blog post
        // and we could go ahead and perform the necessary update
        ....
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Eg. I have following delegate method I want to use as a callback function
I want to use the following method. private void LocationChange(Object obj, int first, int
I want to use following encryption method in C#. but I don't know whether
I want to use the following code to login to a website which returns
I want to use the following command: openssl x509 -noout -in /etc/pki/tls/certs/cert1.pem -enddate openssl
I want preserve original value of target field and use json_decode to use following
Hello Sir i want send list of data to php server i use following
In the following code I want to use the dilate function but I don't
I use the following code to layout network drives on a system. I want
I want to use some basic struct in C like the following: struct p

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.