Solved

Automatically refresh page and revert url to previous page in asp

Posted on 2009-04-09
6
597 Views
Last Modified: 2012-05-06
Hi E.E

To explain I have a script ( that i was kindly helped with) that checks the connection to a database, if it's unable to connect it redirects the customer to an error page that does not require a connection. i'd like to refresh the error page say every 10 seconds, and on the refresh go back to the page where the customer previously was, thus running this procedure untill it connects.

a) Would this be the most efficent way of checking that the connection is now available, by posting back to the original page, loading that page if it fails go back to the error page and repeating the process, or by checking the connection on the error page and once it can connect then redirect the url to the customers original page?

b) I use a global.asa, would it be correct to say i need to create a session variable within that, that could grab and store the current page url, so the error page knows where to return to?

This is deeper than im used to so any help is great.
Thanks
0
Comment
Question by:DanielR6
  • 4
  • 2
6 Comments
 
LVL 4

Assisted Solution

by:rentonc
rentonc earned 50 total points
ID: 24107975
Hi DanielR6,

Would you would need to do is use some javascript in the asp page to count down the refresh and send the user to the other page.
You can use the setTimeout() function in Javascript.

Chris
0
 

Author Comment

by:DanielR6
ID: 24108157
Hi again, oh ok, do i still need to setup a session variable storing the customers original page or would javascript cater for that to?

Dan
0
 
LVL 4

Expert Comment

by:rentonc
ID: 24108192
You could simply use querystrings for the original page variable because each of your pages is ASP and can read the querystring collection.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:DanielR6
ID: 24108730
I found this script, which does the refresh job. Though i have no idea how to include the querystring?
 I take it this could be done with session variables though? I only ask as thats something I'd like to play around with.
var refreshinterval=8

var displaycountdown="yes"

var starttime

var nowtime

var reloadseconds=0

var secondssinceloaded=0
 

function starttime() {

	starttime=new Date()

	starttime=starttime.getTime()

    countdown()

}
 

function countdown() {

	nowtime= new Date()

	nowtime=nowtime.getTime()

	secondssinceloaded=(nowtime-starttime)/1000

	reloadseconds=Math.round(refreshinterval-secondssinceloaded)

	if (refreshinterval>=secondssinceloaded) {

        var timer=setTimeout("countdown()",1000)

		if (displaycountdown=="yes") {

			window.status="Page refreshing in "+reloadseconds+ " seconds"

		}

    }

    else {

        clearTimeout(timer)

		window.location.reload(true)

    } 

}

window.onload=starttime

Open in new window

0
 

Author Comment

by:DanielR6
ID: 24146135
Hi rentonc,

I've been looking at this for sometime now and havn't been able to come up with a fully working solution. So far i have this, but there are some glitches.

I don't know whether it was right to but I added window.history.go(-1) to the else statement to send the page back one step in the history which seems to sort of work, I also changed;  

'Display Error Message to user      
Response.write "An error occurred"
End If

from the pervious piece of code you gave me to ;
'Display Error Message to user
Response.Redirect Server.HTMLEncode("/error_docs/busy.asp")
End If

To send them to the error page if the connection can't be made to the database. The problem I get is that the page on error does go to the error holding page, and the page refreshes untill the connection is available, but when it goes back it seems to jump more than one step back, it goes to the orginal page rather than the page that is trying to be accessed. Im not sure but could it be because if a page gets clicked on, but the connection is down so gets redirected to the holding page it hasn't yet been visited, so its not in the browsers history.

I have also added a session variable to the global.asa if we were able to go down that route.

A bit of assistance on this would be appreciated.

Dan
 
0
 

Accepted Solution

by:
DanielR6 earned 0 total points
ID: 24155790
It seems I now solved it, whether its correct or not im not sure but it works. I was using a response.redirect to transfer the page over to a busy page if the database couldn't connect, however i also created a session variable to store the previous page using HTTP_REFFER. I later found  that the redirect doesnt store in the browser so the reffer can't pick it up, but server.transfer does.

This is the complete code I have. It can probably be much improved on though. Please post improvements if you do.
---------------  global-functions.asp ---------------
 

Place this in an include file for every page that connects to the database;
 

<%

Session("currentpage")= Request.ServerVariables("SCRIPT_NAME")

%>
 

<%

Dim strConnString

Dim db

sub dbconnect(blnswitch)

	Select Case blnswitch

	Case 1

		

		On Error Resume Next

		

                  'Connection name stored in global.asa

		strConnString = Application("ConnName") 
 

		set db = CreateObject("ADODB.Connection")

		

		db.Errors.Clear

		Err.Clear

		db.Open strConnString

		

	Case 0

		db.close

		set db = nothing

	End Select

 

	'Error Handler

	If Err.Number <> 0 Then

            'Clear response buffer

 	    

	Response.Expires = 0 

    Response.Buffer = true 

	Response.Clear

 			

 	    'Redirect the page to the error page

			Server.Transfer("error.asp")
 
 

        End If

 

end sub

%>
 

---------------  global-functions.asp end ---------------
 

---------------  global.asa ---------------

<script language="vbscript" runat="server">

Sub Session_OnStart

	

	'connection string to database

    Application("ConnName") = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _

Mid(Server.MapPath("\"), 1, InStrRev(Server.MapPath("\"),"\")-1) & "mydatabase.mdb;"

	

End Sub
 

Sub Session_OnEnd

	

End Sub
 

Sub Application_OnStart
 

End Sub

</script>

---------------  global.asa end ---------------
 

---------------  error.asp --------------------
 

This goes on holding page;
 

<script type="text/javascript" />

var refreshinterval=5

var displaycountdown="yes"

var starttime

var nowtime

var reloadseconds=0

var secondssinceloaded=0

// Name of session stored in 

var n="<%Session("currentpage")%>";
 
 

function starttime() {

	starttime=new Date()

	starttime=starttime.getTime()

    countdown()

}
 

function countdown() {

	nowtime= new Date()

	nowtime=nowtime.getTime()

	secondssinceloaded=(nowtime-starttime)/1000

	reloadseconds=Math.round(refreshinterval-secondssinceloaded)

	if (refreshinterval>=secondssinceloaded) {

        var timer=setTimeout("countdown()",1000)

		if (displaycountdown=="yes") {

			window.status="Page refreshing in "+reloadseconds+ " seconds"

		}
 

    }

    else {

        clearTimeout(timer)

		location.href= (n)
 

    } 

}

window.onload=starttime
 

</script>

---------------  error.asp end -----------------

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Syntax Help on SP 4 57
Help with stored procedure 30 59
Sorting - Classic asp putting a specific text @ the top of the table 3 40
wordpress display sub menu only when click 12 23
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now