Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making a web site available only for a specified time

Tags:

asp.net

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

like image 773
gout Avatar asked Dec 30 '25 22:12

gout


1 Answers

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 ;    
   }    
}
like image 190
Aristos Avatar answered Jan 02 '26 13:01

Aristos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!