locked
Run my aspx page only on working hours RRS feed

  • Question

  • User-807418713 posted

    Hello

    On Load of my page if IST 7pm to morning 9AM if website open it should say alert message like 

    "Server Is Off Try After 9AM To 7pm IST"

    How To Do So

    Thanking you

    Wednesday, September 4, 2019 7:00 PM

Answers

  • User61956409 posted

    Hi Gopi.MCA,

    To achieve the requirement, as mgebhard suggested, you can check the current time while the request is incoming, then redirect the user to a page that notice user "server is off".

    protected void Application_BeginRequest(object sender, EventArgs e)
    {
        var url = Request.Url.ToString();
    
        if (CheckTime9To19()&&url.ToLower()!= "http://xxxx/home/serveroff")
        {
            Response.Redirect("http://xxxx/Home/ServerOff");
        }
                
    }
    
    private bool CheckTime9To19()
    {
        var h = DateTime.Now.TimeOfDay.Hours;
    
        if (9 <= h && h <= 19)
        {
            return false;
        }
    
        return true;
    }

    With Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, September 5, 2019 2:40 AM

All replies

  • User475983607 posted

    Gopi.MCA

    Hello

    On Load of my page if IST 7pm to morning 9AM if website open it should say alert message like 

    "Server Is Off Try After 9AM To 7pm IST"

    How To Do So

    If your server is off then how do you expect to show a message?

    If the server is not off and you do not want user accessing the site, then write code in the global.asax file (Application_BeginRequest)  that checks the current time. If the time is bwtween 9PM and 7Pm, redirect to your page that alerts the user.

    Wednesday, September 4, 2019 7:03 PM
  • User61956409 posted

    Hi Gopi.MCA,

    To achieve the requirement, as mgebhard suggested, you can check the current time while the request is incoming, then redirect the user to a page that notice user "server is off".

    protected void Application_BeginRequest(object sender, EventArgs e)
    {
        var url = Request.Url.ToString();
    
        if (CheckTime9To19()&&url.ToLower()!= "http://xxxx/home/serveroff")
        {
            Response.Redirect("http://xxxx/Home/ServerOff");
        }
                
    }
    
    private bool CheckTime9To19()
    {
        var h = DateTime.Now.TimeOfDay.Hours;
    
        if (9 <= h && h <= 19)
        {
            return false;
        }
    
        return true;
    }

    With Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, September 5, 2019 2:40 AM