使网站仅在指定时间内可用

时间:2012-03-26 10:54:20

标签: asp.net

是否有可能只在特定时间内提供asp.net网站...? 如何实现它??

3 个答案:

答案 0 :(得分:4)

是的,您可以使用Global.asax

上的BeginRequest执行此操作
protected void Application_BeginRequest(Object sender, EventArgs e)
{
   if(!(DateTime.UtcNow.Hour >= 9 && DateTime.UtcNow.Hour <= 17))
   {
        HttpContext.Current.Response.TrySkipIisCustomErrors = true;
        HttpContext.Current.Response.Write("Even if we are web site, we are open from 9.00 to 17.00 Only! :) <br />Ps If you are the google spider leave a message under the door.");
        HttpContext.Current.Response.StatusCode = 403;
        HttpContext.Current.Response.End();
        return ;    
   }    
}

答案 1 :(得分:1)

根据网站停止时您想要的内容,您可以采用不同的方式进行操作。一个示例是创建一个BasePage类并添加一个代码以在网站关闭时返回404或重定向到错误页面。另一种选择是在Global.asax中订阅Application_BeginRequest事件并在那里做同样的事情。

答案 2 :(得分:0)

在你的global.asax

伪代码:

Session_Start()
{
    If(!CurrentTime in DesiredTimeFrame)
    {
        Redirect to somewhere sensible.  Maybe HTML page explaining why not available.
    }
}