Solved

Response.redirect

Posted on 2002-03-14
7
2,947 Views
Last Modified: 2008-03-10
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.asp") only redirects the frame not the main (parent) window.

I could use a client script but that means another trip. Any ideas??
0
Comment
Question by:innovate
7 Comments
 
LVL 15

Accepted Solution

by:
simonet earned 50 total points
ID: 6863800
Using the Redirect method of the Response object we can redirect to a single page, but we can't target it to a specific frame — only the browser can do that.

The best option is to use a combination of both Server and Client-side scripts.

The best approach is to create dynamic client-side code (in JavaScript or VBScript) which will redirect the top level window to the desired URL, as in:

Response.Write "<SCRIPT LANGUAGE=" & Chr(34) & "VBScript" & Chr(34) & ">" _
                & Chr(13) & Chr(10)
Response.Write "<!--" & Chr(13) & Chr(10)
Response.Write "Sub Window_OnLoad()" & Chr(13) & Chr(10)
Response.Write "On Error Resume Next" & Chr(13) & Chr(10)
strTemp = "Parent.frames(" & Chr(34) & "MainFrame" & Chr(34) _
        & ").location.href = " & Chr(34) & "Option2.asp" & Chr(34)
Response.Write strTemp
Response.Write Chr(13) & Chr(10)
Response.Write "End Sub" & Chr(13) & Chr(10)
Response.Write "-->" & Chr(13) & Chr(10)
Response.Write "</SCRIPT>" & Chr(13) & Chr(10

This will generate the following client-side code:

<SCRIPT LANGUAGE="VBScript">
<!--
Sub Window_OnLoad()
   On Error Resume Next
   Parent.frames("MainFrame").location.href = "Option2.asp"
End Sub
-->
</SCRIPT>



Yours,

Alex
0
 
LVL 15

Expert Comment

by:simonet
ID: 6863803
By the way, the technique described above was extracted from:

Professional Active Server Pages
Wrox Press Ltd.
0
 
LVL 30

Expert Comment

by:third
ID: 6864021


Response.AddHeader "Refresh",CStr(CInt(Session.Timeout + 1) * 60)
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("SERVER_NAME") & _
          Request.ServerVariables("SCRIPT_NAME")

     Temp = Request.ServerVariables("QUERY_STRING")
     If (Not(ISNull(Temp)) AND Temp <> "") Then
          Session("RequestedURL") = Session("RequestedURL") & _
              "?" & Temp
     End If
     Response.Redirect("/login.asp")
End If

http://www.4guysfromrolla.com/webtech/tips/t022800-1.shtml
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 2

Author Comment

by:innovate
ID: 6864143
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="anotherpage.asp"
--></Script>
<%
End If
%>

Which works OK but not what I was hoping, but never mind I suppose.
0
 
LVL 4

Expert Comment

by:vindevogel
ID: 6864571
In a little script ...
window.document.parentwindow.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("SERVER_NAME") & ":" & _
     '                       Request.ServerVariables("SERVER_PORT") & "/SessionEnd.asp"
     'Else
     ' ... code ...
     'End If
     sCurrentPage = Request.ServerVariables("SCRIPT_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("SERVER_NAME") & ":" & _
                            Request.ServerVariables("SERVER_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 ....
0
 
LVL 4

Expert Comment

by:vindevogel
ID: 6864585
By the way: this comes from our development team, a bunch of lazy pro's ....

We only write code once, no copy paste  ;-)
0
 
LVL 4

Expert Comment

by:vindevogel
ID: 6864736
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.parentWindow;

                    if (vFrame.name != 'main')
                         {
                         vFrame.parent.frames("main").navigate('sessionend.asp');

                         if (vFrame.name == 'menu')
                              vFrame.parent.frames('menu').navigate('./menus/emptymenu2.asp')
                         else
                              vFrame.parent.frames('top').navigate('./menus/top.asp')
                         }
                    }

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

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 …
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

760 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