重定向到从全局.asax查看不起作用



如何重定向到从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控制器中添加MaintenancePageGET 操作,如下所示:

[AllowAnonymous]
[HttpGet]
public IActionResult MaintenancePage()
{
return View();
}

然后以这种方式指向此action以防止无限重定向循环:

HttpContext.Current.RewritePath("/Account/MaintenancePage");

希望有帮助。

在维护模式或错误检查的情况下,我使用 Server.Transfer 重定向到静态 html 页面。

Server.Transfer("/Error.html");

我将错误.html保留在项目的根目录中。

最新更新