I have an action filter that validates me if there is a data or this is true
or false
to then redirect to an external url. Redirection works well. But I have the filter in my controller globally and when I enter the controller
for GET
it throws an exception for the @Html.AntiForgeryToken()
that is in a partial view that I call on my page that I'm entering by GET.
My filter class:
public class LogActionFilter : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
bool isBloqueado = true;
if (isBloqueado)
{
filterContext.HttpContext.Response.Redirect("https://www.detacoop.cl", true);
filterContext.HttpContext.ApplicationInstance.CompleteRequest();
return;
}
base.OnActionExecuting(filterContext);
}
}
My Form that is in a partial view, example: _Footer
which is a dependency of my view that I want to render, for example: MyVistaController
@using (Html.BeginForm("LogOff", "Users", FormMethod.Post, new { id = "logoutForm" }))
{
@Html.AntiForgeryToken()
<a href="javascript:document.getElementById('logoutForm').submit()" class="waves-effect waves-light btn-flat u-mar-RL-1 right">Cerrar sesión</a>
}
And throw me the exception here @Html.AntiForgeryToken()
System.Web.HttpException: 'The server can not append a header after sending the HTTP headers.'
Who can help me see why this happens?