gout
gout

Reputation: 812

Making a web site available only for a specified time

Is it possible to make a asp.net website available only during a particular time...? How to implement it..?

Upvotes: 3

Views: 237

Answers (3)

Aristos
Aristos

Reputation: 66641

Yes you can do that using the BeginRequest on Global.asax

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 ;    
   }    
}

Upvotes: 4

Stilgar
Stilgar

Reputation: 23571

Depending on what you want the site to look like when it is down you could do it in different ways. One example would be to create a BasePage class and add a code to return 404 or redirect to error page when the site should be down. Another option is to subscribe for Application_BeginRequest event in Global.asax and do the same thing there.

Upvotes: 1

Paddy
Paddy

Reputation: 33867

In your global.asax

Pseudo code:

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

Upvotes: 0

Related Questions