title: Proper Way to Redirect to controller action/view from .net core 2.1 middleware
body: <p>I have a .NET Core 2.1/Angular 6 application,  I am trying to redirect users to a static view if they are not part of a security group. I just keep getting "Error too many redirects"  when running the app.</p>
  
  <p>I have a <code>securityMiddleWare</code> that is called from <code>Startup.cs</code></p>
  
  <pre><code>public class ADAuthMiddleware
  {
  
      RequestDelegate next;
  
      public ADAuthMiddleware(RequestDelegate next)
      {
  
          this.next = next;
      }
  
      public async Task Invoke(HttpContext httpContext)
      {
          //check if user belongs to AD group or not
          var isAuthorized = httpContext.User.IsInRole("app.users.foo");
  
  
          // Return error if the current user is not authorized
          if (!isAuthorized)
          {
              httpContext.Response.StatusCode = 403;
              return;
          }
  
          // Jump to the next middleware if the user is authorized
          await next(httpContext);
      }
  
  }
  </code></pre>
  
  <p>right now I have it set to return the response of 403,  this just generates the standard ugly "unauthorized page"   so i wanted a cleaner way to send users to a new view where they can get instructions on getting access... <a href="https://i.stack.imgur.com/sFrEU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sFrEU.png" alt="access denied"></a></p>
  
  <p>I've tried <code>httpContext.Response.Redirect(/controller/action)</code> with no luck. 
  this works fine on the full .NET framework with MVC. i've found issues so far with .NET Core..  also maybe because it's running inside a <code>Task</code> instead of <code>IActionResult</code>?  </p>