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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:30:22+00:00 2026-05-20T07:30:22+00:00

I have two tables one with jobs one with managers, when a job ID

  • 0

I have two tables one with jobs one with managers, when a job ID is passed to the view ‘Detail’ the details of that job are accessible.

Job_id  Job_Title       Manager_id
23      Chimney Sweep   65
24      Rat Catcher     84

Managers    Email
65          arthur@work.com
66          fred@work.com

I want to restrict access to the view based on the manager_email – so for example if we’re on http://jobsite/jobs/Detail/23 then only arthur can access the view.. will be using AD to pick out the user’s email..

Any pointers would be much appreciated!

  • 1 1 Answer
  • 2 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-20T07:30:22+00:00Added an answer on May 20, 2026 at 7:30 am

    You could write a custom model binder:

    public class JobModelBinder : DefaultModelBinder
    {
        public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            // fetch the job id from the request
            var jobId = controllerContext.RouteData.Values["id"];
    
            // fetch the currently connected username
            string user = controllerContext.HttpContext.User.Identity.Name;
    
            // Remark: You might need an additional step here
            // to query AD and fetch the email
    
            // Given the job id and the currently connected user, try 
            // to fetch the corresponding job
            Job job = FetchJob(jobId, user);
    
            if (job == null)
            {
                // We didn't find any job that corresponds to
                // the currently connected user
                // => we throw
                throw new HttpException(403, "Forbidden");
            }
            return job;
        }
    
        private Job FetchJob(int jobId, string user)
        {
            throw new NotImplementedException();
        }
    }
    

    and then have your controller:

    public class JobsController : Controller
    {
        [Authorize]
        public ActionResult Show([ModelBinder(typeof(JobModelBinder))]Job job)
        {
            return View(job);
        }
    }
    

    The custom model binder could also be registered in Application_Start:

    protected void Application_Start()
    {
        ...
        ModelBinders.Binders.Add(typeof(Job), new JobModelBinder());
    }
    

    which would simplify your controller action:

    public class JobsController : Controller
    {
        [Authorize]
        public ActionResult Show(Job job)
        {
            // If we get to that point it means that the
            // currently connected user has the necessary
            // permission to consult this view. The custom
            // model binder would have populated the Job model
            // and we can safely pass it to the view for display
            return View(job);
        }
    }
    

    Another advantage of this approach is that you could inject dependencies into the constructor of your custom model binder. It might require those dependencies when tries to communicate with the AD and the database.

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

Sidebar

Related Questions

I have two tables that link together through an id one is submit_moderate and
I have two tables, one that has 450 rows, the other is a Sort
I have two tables: jobs & activities. A job consists of zero or more
I have two tables, one for job deadlines, one for describe a job. Each
I have two tables: one table (okay, it's a view), vComputer, lists many computers
I have two tables one called details and the other called c_details. Both tables
I have two tables: one that stores blogs and the other that stores images
I have two tables one with ID and NAME table 1 ID | NAME
I have two tables one called fs_note the other called dumy_fs_note I created after
i have two tables one is called addons and holds information about different addons,

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.