实施"停机维护"页 [英] Implement "Down for maintenance" page
本文介绍了实施"停机维护"页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道我们可以简单地用一个 app_offline.htm 文件做这一点。
I know we could simply use an app_offline.htm file to do this.
不过,我希望能够访问的网站,如果我的IP是1.2.3.4(例如),这样我可以做最后的测试。
But I want to be able access the website if my IP is 1.2.3.4 (for example), so that I can do a final testing.
if( IpAddress != "1.2.3.4" )
{
return Redirect( offlinePageUrl );
}
我们如何在ASP.NET实现这个MVC 3?
How can we implement this in ASP.NET MVC 3?
推荐答案
您可以使用一个包罗万象的路线与该IP检查的RouteConstraint:
You can use a catch-all route with a RouteConstraint with the IP check:
请确保您先放离线路径。
Make sure you put the offline route first.
routes.MapRoute("Offline", "{controller}/{action}/{id}",
new
{
action = "Offline",
controller = "Home",
id = UrlParameter.Optional
},
new { constraint = new OfflineRouteConstraint() });
和约束code:
public class OfflineRouteConstraint : IRouteConstraint
{
public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
{
// return IpAddress != "1.2.3.4";
}
}
这篇关于实施"停机维护"页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文