title: How to redirect to login page on JWT authentication failed for .net core 3.1 web API
body: <p>I am new to .net core 3.1 and currently working on JWT authentication for web API using .net core and its client side developed using ReactJS. If authenctation fails, how to redirect to my login page or any way to return from custom authorize attribute with unauthorized code(401) for checking at client side. What i tried,</p>
  <pre><code>public void OnAuthorization(AuthorizationFilterContext context)
          {
              ApiResult result = new ApiResult();
              var IsAuthenticated = context.HttpContext.User.Identity.IsAuthenticated;
              var claimsIndentity = context.HttpContext.User.Identity as ClaimsIdentity;
  
              
                  if (IsAuthenticated)
                  {
                      //set custom code
                    
                  }
                  else if (!IsAuthenticated) {
                      Exception ex = new Exception();
                      context.HttpContext.Response.StatusCode = (int)HttpStatusCode.Unauthorized;
                      
                    //need to redirect to Reactjs login page or return from here with unauthorized code 
                  }
             
              return ;
          }
  </code></pre>
  <p>Also tried using startup.cs configure:</p>
  <pre><code>app.UseStatusCodePages(async context =&gt; {
              var request = context.HttpContext.Request;
              var response = context.HttpContext.Response;
  
              if (response.StatusCode == (int)HttpStatusCode.Unauthorized)
              {
                  response.Redirect(&quot;*****&quot;); //my login page is Reactjs page (login.js) or any way to 
                                               return the status code to client 
              }
          });
  </code></pre>