title: Stop Controller constructor execution if invalid authorization
body: <p>I am using Web API project built with c# and I have a few controllers in it.</p>
  
  <p>The controllers have their own constructor methods and in the constructor I am checking for authentication.</p>
  
  <p>When the authentication is successful then it should execute the desired function, if not I want it to return JSON as invalid authorization.</p>
  
  <p>I have the following code in place to do it:-</p>
  
  <pre><code>public class UsersController : Controller
      {
          private RM.Data.IUserData _userData;
  
          private String APIToken = AppConfig.GetConfigValue("APIToken");
  
          public UsersController()
          {
              if (match)
              {
                    // then execute function
              }
              else
              {
                    // stop execution
              }
          }
  
      }
  </code></pre>
  
  <p>I have tried the following things to stop the execution of the function.</p>
  
  <pre><code>return;
  HttpResponse.End();
  System.Threading.Thread.CurrentThread.Interrupt();
  System.Threading.Thread.CurrentThread.Abort();
  System.Web.HttpContext.Current.Response.Close();
  Enviorment.Exit(0);
  Enviorment.Exit(1);
  Enviorment.Exit(-1);
  </code></pre>
  
  <p>Some terminate the app and the others let the api to continue processing.</p>
  
  <p>I have about 50 API and cannot attach this function to each and every API. What can be done in this case.</p>
  
  <p>Nothing worked for me from the above. Can you guys please help?</p>