Error Missing header "Access-Control-Allow-Origin" on the requested resource when redirecting to Action Filter onActionExecuting

I have a problem redirecting to an external URL Requirement I want to redirect to an external URL whenever the session expires.

I have a separate class in which I override the definition of onActionExecuting Action

Here is my code:

public class SessionExpireAttribute : ActionFilterAttribute
{
    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
       // var redirectUrl = "http://www.google.com";
        var isAjaxRequest = filterContext.HttpContext.Request.IsAjaxRequest();

        if (isAjaxRequest)
        {
            filterContext.Result = new RedirectResult("http://www.google.com");
            return;
        }
        base.OnActionExecuting(filterContext);

    }
}

I tried almost all the solutions that I could find in Stack Over Flow, but my problem has not yet been resolved.

Is there any problem with running the conveyor filters of the controller, if that kindly directs me.

A note on the console shows this error.

XMLHttpRequest http://www.google.com/. Access-Control-Allow-Origin . http://localhost:49815 ' .

 public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        var redirectUrl = "http://www.google.com";
        var isAjaxRequest = filterContext.HttpContext.Request.IsAjaxRequest();

        if (isAjaxRequest)
        {
            filterContext.Result = new RedirectToRouteResult(
            new RouteValueDictionary { { "controller", "TestController" }, { "action", "Redirect" } });
            if (filterContext.Result!=null)
            return;
        }
        else
        {
            base.OnActionExecuting(filterContext);
        }

    }

 public class TestController : Controller
{
    public ActionResult Redirect()
    {
        return Redirect("http://www.google.com");
    }
}

.

+4
1

, XMLHttpRequest , . - .

Cross-Origin XMLHttpRequest

CORS

(CORS) - W3C, . XMLHttpRequest, CORS , .

EDIT:

OP, . , :

filterContext.Result = new RedirectToRouteResult(
                new RouteValueDictionary
                    {{"controller", "Home"}, {"action", "Index"}});
+1

Source: https://habr.com/ru/post/1616484/


All Articles