【发布时间】:2015-05-16 17:44:49
【问题描述】:
我收到了一个错误:
((IController)controller).Execute(new RequestContext(new HttpContextWrapper(System.Web.HttpContext.Current), routeData));
System.Web.Mvc.dll 中出现“System.Web.HttpException”类型的异常,但未在用户代码中处理
附加信息:发送 HTTP 标头后服务器无法设置状态。
完整代码如下。
private void RedirectToControllers(string control, string action, bool redirectCheck = false)
{
var routeData = new RouteData();
routeData.Values["controller"] = control;
routeData.Values["action"] = action;
IController controller = null;
if (control == Constants.Alerts)
{
controller = new AlertsController();
}
else if (control == Constants.Account)
{
controller = new AccountController();
}
if (controller != null)
{
if (redirectCheck)
{
((IController)controller).Execute(new RequestContext(new HttpContextWrapper(System.Web.HttpContext.Current), routeData));
// new RedirectResult(Constants.LoginUrl, true);
}
else
{
string returnUrl = System.Web.HttpContext.Current.Request.Url.AbsolutePath;
if (System.Web.HttpContext.Current.Response.RedirectLocation == null)
{
System.Web.HttpContext.Current.Response.Redirect(string.Format("/{0}/{1}?" + returnUrl, ControllerHelper.Controller.ACCOUNT, ControllerHelper.Controller.Action.ACCOUNT_LOGIN));
}
}
}
}
【问题讨论】:
标签: asp.net-mvc controller asp.net-mvc-5