Filtercontext.result new redirectresult error ajaxunauthorized not redirecting

A frustrating issue!

When you're using FilterContext.Result to return a RedirectResult in an ASP.NET Core MVC action, and you're getting an AjaxUnauthorized error, it's likely because the browser is trying to make an AJAX request to the redirect URL instead of following the redirect.

Here are a few possible solutions to help you resolve this issue:

  1. Use Redirect instead of RedirectResult: Try using the Redirect method instead of RedirectResult. This method will automatically set the Location header and return a 302 status code, which should trigger a redirect in the browser.
    return Redirect("/Your/Redirect/Url");
  2. Set the StatusCode property: Make sure to set the StatusCode property of the RedirectResult to 302 (or Found).
    return new RedirectResult("/Your/Redirect/Url", 302);
  3. Use Response.Redirect: You can also use the Response.Redirect method to redirect the request.
    return new EmptyResult();
    Response.Redirect("/Your/Redirect/Url");
  4. Check your AJAX request: If you're making an AJAX request to the action, make sure to set the X-Requested-With header to XMLHttpRequest or false to indicate that it's an AJAX request. This can help the server return a redirect response that the browser will follow.
    $.ajax({
     url: '/Your/Action',
     headers: {
         'X-Requested-With': 'XMLHttpRequest'
     }
    });
  5. Check your browser settings: Some browsers may have settings that prevent them from following redirects. Try checking your browser settings to see if there are any settings that could be preventing the redirect from working.

If none of these solutions work, please provide more details about your code, including the action method, the FilterContext code, and the AJAX request code, and I'll do my best to help you troubleshoot the issue.