I am trying to implement a "Maintenance Mode" into my application. My thought is to "RedirectToRoute" when detected. However, I am getting the following exception:
"localhost redirected you too many times"
I've looked at various online solutions, but none work. Any help is appreciated.
GLOBAL ASAX:
protected void Application_BeginRequest(object sender, EventArgs e)
{
var inMaintenanceMode = false;
bool.TryParse(ConfigurationManager.AppSettings[Settings.Application.Modes.MaintenanceMode], out inMaintenanceMode);
if (inMaintenanceMode)
{
Response.RedirectToRoute("Default", new { controller = "Maintenance", action = "Index" });
Response.End();
return;
}
}
CONTROLLER:
It never gets here...
public class MaintenanceController : Controller
{
// GET: Maintenance
public ActionResult Index()
{
var viewModel = new MaintenanceIndexViewModel();
// Forces a new Session_Start attempt
Session.Abandon();
return View(viewModel);
}
}
为了避免无限重定向循环,您可以在Application_BeginRequest
方法中添加其他检查,以确定当前路由是否为Maintenance
控制器,如果是,请跳过该重定向,因为您已在上一个请求中将其重定向到该路由。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.