如何重定向到从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");
// }
}
}
在Account
控制器中添加MaintenancePage
GET 操作,如下所示:
[AllowAnonymous]
[HttpGet]
public IActionResult MaintenancePage()
{
return View();
}
然后以这种方式指向此action
以防止无限重定向循环:
HttpContext.Current.RewritePath("/Account/MaintenancePage");
希望有帮助。
在维护模式或错误检查的情况下,我使用 Server.Transfer 重定向到静态 html 页面。
Server.Transfer("/Error.html");
我将错误.html保留在项目的根目录中。