Implement Websie SiteDown Notification functionality during maintenance or deployment in asp.net application

Step 1- Add these keys  into web.Config file of your asp.net application.

 <appSettings>
        <add key="IsSiteDown" value="true" />
    <add key="SiteDownStartTime" value="2017/12/07 11:17:00" />
    <!--format yyyy/mm/dd hh:mm:ss-->
    <add key="SiteDownEndTime" value="2017/12/07 11:18:00" />
    <!--format yyyy/mm/dd hh:mm:ss-->    
  </appSettings>
 

Step 2- Add bellow given script and style on master page inside body tag .

<script type="text/javascript">
          $(document).ready(function () 
          {
              var isDown = "<%=ConfigurationManager.AppSettings["IsSiteDown"]%>";
              var SiteDownStartTime = "<%=ConfigurationManager.AppSettings["SiteDownStartTime"]%>";
              var SiteDownEndTime = "<%=ConfigurationManager.AppSettings["SiteDownEndTime"]%>";
              var startTime = "<%=ConfigurationManager.AppSettings["SiteDownStartTime"]%>"
              var countDownDate = new Date(startTime).getTime();
              var currentTime = Date();
              var cdDt = new Date(Date.parse(currentTime, "yyyy/MM/dd HH:mm z"));
              var end = new Date(Date.parse(SiteDownEndTime, "yyyy/MM/dd HH:mm z"));
              if (isDown && cdDt > end) 
              {
                  isDown = false;
                  $("#divDowntime").css('visibility''hidden');
              }
              else {
                  var x = setInterval(function () {  
                      var now = new Date().getTime();
                      var distance = countDownDate - now;
                      var days = Math.floor(distance / (1000 * 60 * 60 * 24));
                      var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
                      var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
                      var seconds = Math.floor((distance % (1000 * 60)) / 1000);
                      // Output the result in an element with id="demo"
                      if (document.getElementById("Ctimer") != null || document.getElementById("Ctimer") != undefined) {
                          document.getElementById("Ctimer").innerHTML = days + "d " + hours + "h "
                          + minutes + "m " + seconds + "s ";
                          // If the count down is over, write some text
                          if (distance < 0) {
                              clearInterval(x);
                              document.getElementById("Ctimer").innerHTML = "EXPIRED";
                               location.reload();
                          }
                      }
                  }, 1000);
                  $("#divDowntime").css('visibility''visible');
              }
      });
    </script>
 
 
<style type="text/css">
      .countdown {
          displayblock;
          positionfixed;
          right0;
          z-index1000;
          background#fff;
          padding10px 15px;
          top50%;
          width300px;
          max-width100%;
          -moz-border-radius4px 0 0 4px;
          -webkit-border-radius4px 0 0 4px;
          border-radius4px 0 0 4px;
          -moz-box-shadow0 0 4px #333;
          -webkit-box-shadow0 0 4px #333;
          box-shadow0 0 4px #333;
      }
 
          .countdown b {
              color#fe8611;
              font-size18px;
          }
 
          .countdown p {
              displayinline-block;
              font-size12px;
              vertical-aligntop;
              margin-bottom0;
              line-height18px;
          }
 
          .countdown i {
              font-size40px;
              color#ff8613;
          }
  </style>
 
 
<div class="countdown" id="divDowntime" style="visibility: hidden">
           <i class="fa fa-warning"></i>
           <p>Website maintenance scheduled in
               <br />
               <b id="Ctimer">0d 0h 0m 0s</b>, Sorry for the
               <br />
               inconvenience. </p>
</div>
 

 
 
Step 3-

Create html page to show downtime message at the time of downtime and name that page Maintenance.html” (you can given any name).
 
Step 4 – Goto Global.asax.cs  file and add given code in Application _BeginRequest () event .

protected void Application_BeginRequest(object sender, EventArgs e)
       {
           var maintenancePage = System.Web.Hosting.HostingEnvironment.MapPath("~/src/UI/Maintenance.htm");
           var isSiteDown = Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["IsSiteDown"]);
           var siteDownStartTimeStr = System.Configuration.ConfigurationManager.AppSettings["SiteDownStartTime"].ToString();
           var siteDownEndTimeStr = System.Configuration.ConfigurationManager.AppSettings["SiteDownEndTime"].ToString();
           var siteDownStartTime = DateTime.Parse(siteDownStartTimeStr);
           var siteDownEndTime = DateTime.Parse(siteDownEndTimeStr);
           var currentTime = DateTime.Now;
           if (isSiteDown && (currentTime >= siteDownStartTime && currentTime < siteDownEndTime))
           {
               Response.RedirectPermanent("~/src/UI/Maintenance.htm");
           }

       }

 

Steps 5  - Now to set Website Temporary  Site Down  change the Site down Date & time in web.config   properties according to you (Properties added into first step).