Website creation is only available for a specific time period
Is it possible to make the asp.net site only available at certain times ...? How to implement it ..?
+3
gout
source
to share
3 answers
Yes, you can do this using 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 ;
}
}
+4
Aristos
source
to share
Depending on what you want the site to look like when it's down, you can do it in different ways. One example would be creating a BasePage class and adding code to return a 404, or redirecting to an error page when the site should be down. Another option is to subscribe to the Application_BeginRequest event in Global.asax and do the same.
+1
Stilgar
source
to share
In your global.asax
Pseudocode:
Session_Start()
{
If(!CurrentTime in DesiredTimeFrame)
{
Redirect to somewhere sensible. Maybe HTML page explaining why not available.
}
}
0
Paddy
source
to share