Link to home
Start Free TrialLog in
Avatar of Jerry Miller
Jerry MillerFlag for United States of America

asked on

Take web site down for maintenance

I have a requirement in a web application that I am developing in VB.Net to have the ability to take the site offline for maintenance. I have that part down by storing a Boolean value in a table and checking it on the page load of the pages that should be offline. This works fine as it only allows people in the proper roles to access the necessary pages.

However, I need to warn the users that the site is going down in specified amount of time regardless of what page they are on and then have it be unavailable. Can someone direct me on the best way to give the logged in users a pop-up message or other visual notification that they need to save their work because the site is going down?
ASKER CERTIFIED SOLUTION
Avatar of Doug
Doug
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Jerry Miller

ASKER

Thanks for the help, I had a huge mental block and couldn't come up with any ideas. I took your second idea and ran with it a bit. Here is what I did:

1)  I put a label on the master page and pulled the datetime / status from the database. This is to display a message to the user what time the system would be unavailable.

Dim implementTime As Date?
        Dim maintenance As Boolean
        Dim projectDBO As New ProjectDataBO
        Dim dataset2 As SqlDataReader = projectDBO.getIsMaintenanceMode()
        Dim message As String = "The system is going down for maintenance at "
        Dim message2 As String = ". Please save your work and log out"
        If dataset2.HasRows Then
            While dataset2.Read()
                If Not dataset2("implementTime") Is DBNull.Value Then
                    implementTime = dataset2("implementTime")
                    maintenance = dataset2("IsMaintenanceMode")
                End If

            End While
        End If
        If maintenance = True Then
            Me.lblMessage.Font.Bold = True
            Me.lblMessage.BackColor = Drawing.Color.Red
            Me.lblMessage.Text = message & implementTime.ToString
        End If

2)  I updated my previous IsMaintenanceMode code on my configurations page to pull in the date as well. This returns true when the date has passed and the flag is true in the database. I added a date field in my database to determine what time to set the system in maintenance mode.

Public Shared ReadOnly Property isMaintenanceMode() As Boolean
            Get
                Dim maintenance As Boolean
                Dim implementTime As Date?
                Dim projectDBO As New ProjectDataBO
                Dim dataset As SqlDataReader = projectDBO.getIsMaintenanceMode()
                If dataset.HasRows Then
                    While dataset.Read()
                        maintenance = dataset("IsMaintenanceMode")
                        If Not dataset("implementTime") Is DBNull.Value Then
                            implementTime = dataset("implementTime")
                        End If

                    End While
                End If
                If implementTime > Now() OrElse implementTime Is Nothing Then
                    Return False
                Else
                    Return maintenance
                End If

            End Get
        End Property

3) Then on each page that needs to be inactive, I add this code. I was already doing this step, so it doesn't require changes across the pages that I have completed. MAINTENANCE_PAGE is a constant that maps to the true URL.

If Configurations.isMaintenanceMode Then
            HttpContext.Current.Response.Redirect(MAINTENANCE_PAGE, False)
End If

A lot of this is because the supervisor that will perform certain functions needs to ensure that the data isn't being updated while they are working. Plus it gives anyone that is working a few minutes before the system is locked. They get the red warning label across the top of the page and after the time has elapsed, the system locks them out.
Thanks again for the kick in the brain to get me going!
You're welcome.  We all need those sometimes.  Glad I could help.