innovate
asked on
Response.redirect
I have a page in a frame and if the user times out I want to redirect them to the logon page
response.redirect("logon.a sp") only redirects the frame not the main (parent) window.
I could use a client script but that means another trip. Any ideas??
response.redirect("logon.a
I could use a client script but that means another trip. Any ideas??
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Response.AddHeader "Refresh",CStr(CInt(Sessio
Response.AddHeader "cache-control", "private"
Response.AddHeader "Pragma","No-Cache"
Response.Buffer = TRUE
Response.Expires = 0
Response.ExpiresAbsolute = 0
If (Session("Authenticated") <> Session.SessionID) Then
Session("RequestedURL") = "http://" & _
Request.ServerVariables("S
Request.ServerVariables("S
Temp = Request.ServerVariables("Q
If (Not(ISNull(Temp)) AND Temp <> "") Then
Session("RequestedURL") = Session("RequestedURL") & _
"?" & Temp
End If
Response.Redirect("/login.
End If
http://www.4guysfromrolla.com/webtech/tips/t022800-1.shtml
ASKER
As mentioned I can do it on the client side, I was doubtful that it could be done on the server side.
What I've got is..
</head>
<%
If GotoADifferentPage then
%>
<Script language="javascript"><!--
parent.location.href="anot herpage.as p"
--></Script>
<%
End If
%>
Which works OK but not what I was hoping, but never mind I suppose.
What I've got is..
</head>
<%
If GotoADifferentPage then
%>
<Script language="javascript"><!--
parent.location.href="anot
--></Script>
<%
End If
%>
Which works OK but not what I was hoping, but never mind I suppose.
In a little script ...
window.document.parentwind ow.parent. navigate yourpage.asp
BUT
It might be better to do this in your global.asa
<SCRIPT LANGUAGE=VBScript RUNAT=Server>
Sub Session_OnStart
'Make sure that new users start on the correct page of the ASP application
Const csStartPage = "/user.asp"
Const csLoginPage = "/Login.asp"
Const csIndexPage = "/index.asp"
Const csReStartPage = "/SessionEnd.asp"
Dim sCurrentPage
'This replaces the following code in the beginning of EVERY ASP-page
'If Session("User") = "" Then
' Response.Redirect "http://" & Request.ServerVariables("S ERVER_NAME ") & ":" & _
' Request.ServerVariables("S ERVER_PORT ") & "/SessionEnd.asp"
'Else
' ... code ...
'End If
sCurrentPage = Request.ServerVariables("S CRIPT_NAME ")
If not((strcomp(sCurrentPage, csStartPage, 1) = 0) OR _
(strcomp(sCurrentPage, csIndexPage, 1) = 0) OR _
(strcomp(sCurrentPage, csLoginPage, 1) = 0)) Then
Response.Redirect "http://" & Request.ServerVariables("S ERVER_NAME ") & ":" & _
Request.ServerVariables("S ERVER_PORT ") & csReStartPage
End If
End Sub
</SCRIPT>
What it does ....
When a session times out, and the user then clicks a link, a new session will start. You trap this in your global.asa
Then you check what page the user wants (index and login page are ok, this means homepages, any other= session time out) And then you redirect ....
This way, you must not code it in every page ....
window.document.parentwind
BUT
It might be better to do this in your global.asa
<SCRIPT LANGUAGE=VBScript RUNAT=Server>
Sub Session_OnStart
'Make sure that new users start on the correct page of the ASP application
Const csStartPage = "/user.asp"
Const csLoginPage = "/Login.asp"
Const csIndexPage = "/index.asp"
Const csReStartPage = "/SessionEnd.asp"
Dim sCurrentPage
'This replaces the following code in the beginning of EVERY ASP-page
'If Session("User") = "" Then
' Response.Redirect "http://" & Request.ServerVariables("S
' Request.ServerVariables("S
'Else
' ... code ...
'End If
sCurrentPage = Request.ServerVariables("S
If not((strcomp(sCurrentPage,
(strcomp(sCurrentPage, csIndexPage, 1) = 0) OR _
(strcomp(sCurrentPage, csLoginPage, 1) = 0)) Then
Response.Redirect "http://" & Request.ServerVariables("S
Request.ServerVariables("S
End If
End Sub
</SCRIPT>
What it does ....
When a session times out, and the user then clicks a link, a new session will start. You trap this in your global.asa
Then you check what page the user wants (index and login page are ok, this means homepages, any other= session time out) And then you redirect ....
This way, you must not code it in every page ....
By the way: this comes from our development team, a bunch of lazy pro's ....
We only write code once, no copy paste ;-)
We only write code once, no copy paste ;-)
Oyeah. We display a normal page, a warning page, and in that page, we redirect after 5 seconds to the complete login screen.
This is the script in that page that checks the frames
if (window.frames.length > 1)
{
var vFrame = window.document.parentWind ow;
if (vFrame.name != 'main')
{
vFrame.parent.frames("main ").navigat e('session end.asp');
if (vFrame.name == 'menu')
vFrame.parent.frames('menu ').navigat e('./menus /emptymenu 2.asp')
else
vFrame.parent.frames('top' ).navigate ('./menus/ top.asp')
}
}
This is the script in that page that checks the frames
if (window.frames.length > 1)
{
var vFrame = window.document.parentWind
if (vFrame.name != 'main')
{
vFrame.parent.frames("main
if (vFrame.name == 'menu')
vFrame.parent.frames('menu
else
vFrame.parent.frames('top'
}
}
Professional Active Server Pages
Wrox Press Ltd.