title: How to return the view of a controller that is protected with Authorize (JWT)?
body: <p>I am working with ASP.NET Core MVC and JWT. After getting the token from localstorage and making a request to a controller that is protected with <code>[Authorize]</code> and manages to enter and validate the token, it does not open the index of that controller - it does not redirect it to that controller's page. The result I get is the HTML script and then Unauthorized 401. How can this be solved?</p>
  
  <p>This is my JavasSript code:</p>
  
  <pre class="lang-js prettyprint-override"><code>var apiUrl = "http://localhost:61545/User/Index";
  $("#btntest").click(function () 
      $.ajax({
          type: "get",
          url: apiUrl,
          beforeSend: function (xhr) {
              xhr.setRequestHeader("Authorization", "Bearer " + localStorage.getItem("token"));
          },
          success: function () {
              alert("enter")
              window.open("/User/Index");
          },
          error: function () {
              alert('wrong!');
          }
      })
  })
  </code></pre>
  
  <p>Here's the controller:</p>
  
  <pre><code>public class UserController : Controller
  {
      [HttpGet]
      [Authorize]
      public ActionResult Index()
      { 
          return View();
      }
  }
  </code></pre>