title: ASP.NET.MVC 5 Adding permissions to action of a controller
body: <p>I have project with Windows Authentication and with a controller I have a question, by that controller below, I can get information by specifying the name of branch (by typing URL into a browser address bar for example):</p>
  
  <p>"<a href="http://localhost:62249/Students/TestNew/Branch1" rel="nofollow noreferrer">http://localhost:62249/Students/TestNew/Branch1</a>"; </p>
  
  <p>And it will display to the user data where branch = Branch1. </p>
  
  <p>Now the question is - how can I achieve the following?</p>
  
  <p>For each branchname I want specify permission to allow open this page by specifying group from ActiveDirectory. Or it's impossible and I should create 10 more controllers and specify there permission for each one.</p>
  
  <pre><code>    [HttpGet]
      public ActionResult TestNew(string branchname)
      {
          // check stuff like permissions
          var db = new MovieContext();
          var model = new Model();
  
  
          var students = db.Student
              .Where(x =&gt; x.BranchName == branchname)
              .GroupBy(x =&gt; new { x.BranchName, x.Name, x.Currency, x.NoCart, x.NoAccount })
              .Select(x =&gt; new
              {
                  BranchName = x.FirstOrDefault().BranchName,
                  Name = x.FirstOrDefault().Name,
                  A_Status = x.Max(p =&gt; p.A_Status),
                  Currency = x.FirstOrDefault().Currency,
                  NoCart = x.FirstOrDefault().NoCart,
                  NoAccount = x.FirstOrDefault().NoAccount
              }).ToList();
          foreach (var item in students)
          {
              model.Students.Add(new Student
              {
                  A_Status = item.A_Status,
                  BranchName = item.BranchName,
                  Name = item.Name,
                  NoAccount = item.NoAccount,
                  NoCart = item.NoCart,
                  Currency = item.Currency
  
              });
          }
          return View(model);
  </code></pre>