【发布时间】:2019-02-24 00:59:33
【问题描述】:
如何从 global.asax 重定向到视图?
下面是我的代码。它给了我 HTTP 错误 500.19 - 内部服务器错误。
public void Application_BeginRequest(object sender, EventArgs e)
{
if (ConfigurationManager.AppSettings["MaintenanceMode"] == "true")
{
// if (!Request.IsLocal)
// {
Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoStore();
Server.ClearError();
Response.Clear();
HttpContext.Current.Response.Redirect("~/Views/Account/MaintenancePage.cshtml");
// }
}
}
【问题讨论】:
-
试试
HttpContext.Current.Response.Redirect("/Account/MaintenancePage"); -
我试过了。但它显示“页面未正确重定向”
-
尝试将 false 传递给第二个参数,例如
HttpContext.Current.Response.Redirect("/Account/MaintenancePage", false);。另外,确保/Account/MaintenancePage是有效的网址 -
试过了。相同的消息““页面没有正确重定向”:-(
-
并且您已经确认可以在浏览器中浏览到
/Account/MaintenancePage?
标签: c# asp.net asp.net-mvc iis