C# 从global.asax重定向到视图不工作
如何从global.asax重定向到视图 下面是我的代码。它给了我HTTP错误500.19-内部服务器错误C# 从global.asax重定向到视图不工作,c#,asp.net,asp.net-mvc,iis,C#,Asp.net,Asp.net Mvc,Iis,如何从global.asax重定向到视图 下面是我的代码。它给了我HTTP错误500.19-内部服务器错误 public void Application_BeginRequest(object sender, EventArgs e) { if (ConfigurationManager.AppSettings["MaintenanceMode"] == "true") { // if (!Request.IsLocal)
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");
// }
}
}
在您的
帐户
控制器中添加MaintenancePage
获取操作,如下所示:
[AllowAnonymous]
[HttpGet]
public IActionResult MaintenancePage()
{
return View();
}
然后以这种方式指向此操作
,以防止无限重定向循环:
HttpContext.Current.RewritePath("/Account/MaintenancePage");
希望对您有所帮助。添加
维护页面
在您的帐户
控制器中获取操作,如下所示:
[AllowAnonymous]
[HttpGet]
public IActionResult MaintenancePage()
{
return View();
}
然后以这种方式指向此操作
,以防止无限重定向循环:
HttpContext.Current.RewritePath("/Account/MaintenancePage");
希望有帮助。在维护模式或错误检查的情况下,我使用Server.Transfer重定向到静态html页面
Server.Transfer("/Error.html");
我将Error.html保存在项目的根目录中。在维护模式或错误检查的情况下,我使用Server.Transfer重定向到静态html页面
Server.Transfer("/Error.html");
我将Error.html保存在项目的根目录中。Try
HttpContext.Current.Response.Redirect(“/Account/MaintenancePage”)我试过了。但它显示“页面没有正确重定向”,请尝试将false传递给第二个参数,如HttpContext.Current.Response.Redirect(“/Account/MaintenancePage”,false)代码>。此外,请确保/Account/MaintenancePage
有效。同一消息“页面未正确重定向”:(您已检查是否可以在浏览器中浏览到/Account/MaintenancePage
?尝试HttpContext.Current.Response.Redirect(“/Account/MaintenancePage”);
我尝试过。但它显示“页面未正确重定向”“尝试将false传递给第二个参数,如HttpContext.Current.Response.Redirect(“/Account/MaintenancePage”,false);
。此外,确保/Account/MaintenancePage
有效。同一消息”“页面未正确重定向”:-(并且您已检查是否可以在浏览器中浏览到/Account/MaintenancePage
?如果您已经来自“/Account/MaintenancePage”,则会出现StackOverflow异常签入应用程序\u BeginRequest
方法“如何检查?我已检查。没有我在帐户/索引ExpageIt给我StackOverflow例外签入应用程序\u BeginRequest
方法(如果您已经来自“/account/MaintenancePage”如何检查?我检查了。不,我在帐户/索引页它是一个MVC应用程序。因此,我不在根目录中创建一个视图内部的视图/帐户折叠,静态页面只是一个文件,所以为了维护的目的,考虑这个场景而不是控制器动作是有意义的。已经有一个视图文件夹。我不想T。o复制视图。它是一个MVC应用程序。因此,我不在根目录中创建视图/帐户折叠视图中的一个视图,静态页面只是一个文件,所以为了维护目的,考虑这个场景而不是控制器动作是有意义的。已经有一个视图文件夹。我不想复制视图。