Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1014
  • Last Modified:

Breaking out of a Frame VBScript - onload logout when cookie expires

I have a page (2.asp) that loads within the "Mainframe" of an existing page (frames.asp). When 2.asp loads, I want this page to check if the permission in cookie is set for the page to load. If found false, it should break out of the frame and load logout.asp

The cookie was first set on the loginnow.asp with this code.
<%response.buffer=true
response.cookies("module").Expires=date + 1
response.cookies("module")("permission")= "yes" %>

On 2.asp the onload() function body checks if the permission is still "yes"

<script type="text/vbscript">
function onload()
 permission1=request.cookies("module")("permission")
  if permission1 = "" or permission2="no" then
    javas()
  end if
end function
</script>

javas() is a javascript which is

<script type="text/javascript">
function javas()
{
  if (window.top != window.self)
   {
    window.top.location="logout.asp"
   }
}
</script>

Unfortunately, this doesnt work! Is there a way to break out of a frame in VBScript. Also the error is on Request.cookies !!

Is there is something wrong in my code? I would appreciate if you can help me out with this.
0
sciber_dude
Asked:
sciber_dude
  • 5
  • 3
1 Solution
 
heronganCommented:
You try following code:

=============================================
<%response.buffer=true
response.cookies("module").Expires=date + 1
response.cookies("module")("permission")= "no"
%>

<html>

<script language="vbscript">
function window_onLoad()
permission1="<%=request.cookies("module")("permission")%>"
 if permission1 = "" or permission1="no" then
   javas()
 end if
end function
</script>

<script language="javascript">
function javas()
{
   top.window.location="logout.asp"
}
</script>

<body>
</body>
</html>

=============================================
0
 
heronganCommented:
If you want to check the current window is the top or not, you can use following code.

if (self!=top) // self isn't the top
{
  top.window.location="logout.asp"
}

But i don't know why you need to check it?

Hope can help!
0
 
heronganCommented:
"request" is a server-side object.
Your VBScript is a client-side script.
For this reason, the error will occur when you trying to get a cookie via "request.cookies".
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
sciber_dudeAuthor Commented:
Herogan,
Thank you for your replies. It did help me find the solution. "request" is a server-side object. This was cause of the problem.

I have found the solution to my problem:-

1. I've included the following line to 2.asp before <HTML> tag
<!--#include file="checkpermission.asp"-->

2. I have created a new page called checkpermission.asp and have written the following code
<%
response.buffer=true
permission1=request.cookies("module")("permission")

if permission1 = "" or permission1 = "no" then
 Response.Redirect "logout.asp"
end if
%>

3. On the logout.asp page, I have added the following Javascript which has an 'onload' function. This breaks this page out of the frames.
<script type="text/javascript">
function javas()
{
 if (window.top != window.self)
  {
   window.top.location="logout.asp"
  }
}
</script>

The advantage of this technique is that I dont have to write 'permission checking' code on all the pages in the module. Adding just the #include line will do the job.

This is the first time I have asked a question on this forum. Even though your answer has not given me the exact solution to my question, I should give you credit for showing me the right direction.

Thanks.
0
 
sciber_dudeAuthor Commented:
How do I award the points / grade?
0
 
heronganCommented:
After you answer the question, if the answer can help someone to solve the problem. He/She will click "Accept Comment As Answer"(Can you see this word on my posted message?). Then you will gain a expert point.

Hence, pls click the "Accept Comment As Answer" to give me a expert point.HaHa =)

Hero
0
 
heronganCommented:
Besides it, the "Available Question Points" will auto increase 5 points for each day.
Or you can spend $$ to buy.
0
 
sciber_dudeAuthor Commented:
Thank you for you help!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now