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 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");
}
}
.