我有一个自我更新的应用程序 - 意味着有一个视图,用户可以选择更新包,如果可用,appliaction将安装它(添加文件,删除文件或覆盖现有文件)。此更新可能需要一段时间,我想将可能来到应用程序的所有新请求重定向到网站 - 无法使用 - 因为正在更新正在进行中页。我的猜测是我无法重定向正在进行的请求,但也许有一种方法可以暂停更新,直到所有请求都完成并阻止传入的请求并在完成后启动它。有什么提示吗?
答案 0 :(得分:1)
试试这个:
第1步:设置一个表示您正在“更新”的环境 第2步:创建路由处理程序
public class UpdatingRouteHandler: MvcRouteHandler
{
protected override IHttpHandler GetHttpHandler(RequestContext Context)
{
//Check if environment var is set to 'updatestate'
if ( updatestate)
{
Context.RouteData.Values["controller"] = "LandingPage";
Context.RouteData.Values["action"] = "Index";
}
return base.GetHttpHandler(Context);
}
}
第3步:将MVCRouteHandler添加到路由
routes.MapRoute(
name: "Landingpage",
url: "Landingpage/{id}/{*dummy}",
defaults: new { controller = "Landingpage", action = "Index" }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
).RouteHandler = new UpdatingRouteHandler();
它仍然是MVC所以如果没有任何装载,将不会显示任何内容。
另一条路径可能是在Global.asax中实现Application_BeginRequest()并从那里重定向。