Solved

Automatically refresh page and revert url to previous page in asp

Posted on 2009-04-09
6
602 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Classic ASP, Search Recordset on pick list change 1 71
asp syntax 3 56
Passing Parameter to Stored Procedure 4 27
Html CheckBox obtain Its Value 5 27
I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

840 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