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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:14:23+00:00 2026-06-15T19:14:23+00:00

I’m using ASP.NET/MVC and need to add some security measures to the ActionResult/ViewResult controller

  • 0

I’m using ASP.NET/MVC and need to add some security measures to the ActionResult/ViewResult controller methods. Basically I need to make sure the user is associated with the same organisation associated with the page, what level of access they have and redirect them if required.

I would typically use attributes for this but need to use some business logic to determine where to return view/redirect, and I need to initialise a non constant user defined object with a query string value before doing it. I want to centralise the logic by maybe using a helper class (open to suggestions) but I’m not sure how to access the context/make the redirect from the helper class.

E.g., page action is like…

public ActionResult Index(string id)
{
            Models.Bucket bucket = new Bucket();
            InitBucket(bucket, id);

            SecurityHelper.UserOrganisationMatchesObjectOrganisation(CurrentUser, bucket);
}

and in the SecurityHelper

    public static void UserOrganisationMatchesObjectOrganisation(Model.User user, Bucket bucket)
    {
       //if various logic in user and bucket occur return View("NewPage", bucket)

       //else return RedirectResult("~/yournotallowed")
    }

Only thing is you can’t redirect/return view in the helper method without context, and not sure how to pass it from the controller to the helper class or whether thats possible.

I’m sure there is a better way of doing this like using a service, or using attributes and being able to pass my initialised bucket object in.

Any suggestions welcome!

Thanks

  • 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-15T19:14:24+00:00Added an answer on June 15, 2026 at 7:14 pm

    I might be missing something here, but isn’t it just a case of returning an ActionResult from your UserOrganisationMatchesObjectOrganisation method? I would perhaps change the name of it so it’s a bit more obvious what the method is going to do e.g.

    public static class Security
    {
        public static ActionResult GetActionResultForUser(Model.User user, Bucket bucket)
        {
            //if various logic in user and bucket occur return View("NewPage", bucket)
            //else return RedirectResult("~/yournotallowed")    
        }   
    }
    
    ...
    public ActionResult Index(string id)
    {
        Models.Bucket bucket = new Bucket();
        InitBucket(bucket, id);
        return Security.GetActionResultForUser(CurrentUser, bucket);
    }
    

    Another approach could be to introduce a Service class which could return some sort of state (or throw an exception) which you could then use to determine which view to return e.g.

    private BucketService _bucketService = new BucketService();
    ...
    
    public ActionResult Index(string id)
    {
        try
        {
            var bucket = _bucketService.GetBucketForUser(CurrentUser, id);
            return View("NewPage", bucket);
        }
        catch (InsufficientPriviledgesException)
        {
            return RedirectResult("~/yournotallowed");
        }
    }
    

    The benefit of this approach as it keeps a clean separation between your business & presentation logic.

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

Sidebar

Related Questions

I have thousands of HTML files to process using Groovy/Java and I need to
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
In my XML file chapters tag has more chapter tag.i need to display chapters
We're building an app, our first using Rails 3, and we're having to build

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.