title: ASP.NET MVC Attribute to only let user edit his/her own content
body: <p>I have a controller method called <code>Edit</code> in which the user can edit data they had created like so ...</p>
  
  <pre><code>public ActionResult Edit(int id)
  {
      Submission submission = unit.SubmissionRepository.GetByID(id);
      User user = unit.UserRepository.GetByUsername(User.Identity.Name);
  
      //Make sure the submission belongs to the user
      if (submission.UserID != user.UserID)
      {
          throw new SecurityException("Unauthorized access!");
      }
  
      //Carry out method
  }
  </code></pre>
  
  <p>This method works fine however it is a little messy to put in every controller Edit method. Each table always has a <code>UserID</code> so I was wondering if there was an easier way to automate this via an <code>[Authorize]</code> Attribute or some other mechanism to make the code cleaner.</p>