title: Redirect to login page vs throwing 'Authorization Required' error page (Azure AD Graph MVC 5)
body: <p>I have a MVC 5 project that is structured similar to this sample code: <a href="https://github.com/Azure-Samples/active-directory-dotnet-graphapi-web" rel="nofollow noreferrer">https://github.com/Azure-Samples/active-directory-dotnet-graphapi-web</a>.</p>
  
  <p>Whenever the Application Pool recycles, it throws an error 'Authorization Required' and displays the stack trace. This is where it executes within the code:</p>
  
  <p>ProjectName/Utils/AuthenticationHelper.cs</p>
  
  <pre><code>namespace ProjectName.Utils
  {
      internal class AuthenticationHelper
      {
          public static string token;
  
          /// &lt;summary&gt;
          ///     Async task to acquire token for Application.
          /// &lt;/summary&gt;
          /// &lt;returns&gt;Async Token for application.&lt;/returns&gt;
          public static async Task&lt;string&gt; AcquireTokenAsync()
          {
              if (token == null || token.IsEmpty())
              {
                  throw new Exception("Authorization Required.");
              }
              return token;
          }
  
          /// &lt;summary&gt;
          ///     Get Active Directory Client for Application.
          /// &lt;/summary&gt;
          /// &lt;returns&gt;ActiveDirectoryClient for Application.&lt;/returns&gt;
          public static ActiveDirectoryClient GetActiveDirectoryClient()
          {
              Uri baseServiceUri = new Uri(Constants.ResourceUrl);
              ActiveDirectoryClient activeDirectoryClient =
                  new ActiveDirectoryClient(new Uri(baseServiceUri, Constants.TenantId),
                      async () =&gt; await AcquireTokenAsync());
              return activeDirectoryClient;
          }
      }
  }
  </code></pre>
  
  <p>How do I redirect the user to the login page instead of <code>throw new Exception("Authorization Required.");</code> ?</p>
  
  <p>Thank you for the help or insight in advance.</p>