Can any help me, I am getting an error in below line.
((IController)c ontroller).Exec ute(new RequestContext( new HttpContextWrap per(System.Web. HttpContext.Cur rent), routeData));
Error: An exception of type 'System.Web.Htt pException' occurred in System.Web.Mvc. dll but was not handled in user code
Additional information: Server cannot set status after HTTP headers have been sent.
The full code as given below.
private void RedirectToContr ollers(string control, string action, bool redirectCheck = false)
{
var routeData = new RouteData();
routeData.Value s["controller "] = control;
routeData.Value s["action"] = action;
IController controller = null;
if (control == Constants.Alert s)
{
controller = new AlertsControlle r();
}
else if (control == Constants.Accou nt)
{
controller = new AccountControll er();
}
if (controller != null)
{
if (redirectCheck)
{
((IController)c ontroller).Exec ute(new RequestContext( new HttpContextWrap per(System.Web. HttpContext.Cur rent), routeData));
// new RedirectResult( Constants.Login Url, true);
}
else
{
string returnUrl = System.Web.Http Context.Current .Request.Url.Ab solutePath;
if (System.Web.Htt pContext.Curren t.Response.Redi rectLocation == null)
{
System.Web.Http Context.Current .Response.Redir ect(string.Form at("/{0}/{1}?" + returnUrl, ControllerHelpe r.Controller.AC COUNT, ControllerHelpe r.Controller.Ac tion.ACCOUNT_LO GIN));
}
}
}
}
Thank you!!
http://www.code-sample.com/
((IController)c ontroller).Exec ute(new RequestContext( new HttpContextWrap per(System.Web. HttpContext.Cur rent), routeData));
Error: An exception of type 'System.Web.Htt pException' occurred in System.Web.Mvc. dll but was not handled in user code
Additional information: Server cannot set status after HTTP headers have been sent.
The full code as given below.
private void RedirectToContr ollers(string control, string action, bool redirectCheck = false)
{
var routeData = new RouteData();
routeData.Value s["controller "] = control;
routeData.Value s["action"] = action;
IController controller = null;
if (control == Constants.Alert s)
{
controller = new AlertsControlle r();
}
else if (control == Constants.Accou nt)
{
controller = new AccountControll er();
}
if (controller != null)
{
if (redirectCheck)
{
((IController)c ontroller).Exec ute(new RequestContext( new HttpContextWrap per(System.Web. HttpContext.Cur rent), routeData));
// new RedirectResult( Constants.Login Url, true);
}
else
{
string returnUrl = System.Web.Http Context.Current .Request.Url.Ab solutePath;
if (System.Web.Htt pContext.Curren t.Response.Redi rectLocation == null)
{
System.Web.Http Context.Current .Response.Redir ect(string.Form at("/{0}/{1}?" + returnUrl, ControllerHelpe r.Controller.AC COUNT, ControllerHelpe r.Controller.Ac tion.ACCOUNT_LO GIN));
}
}
}
}
Thank you!!
http://www.code-sample.com/
Comment