Solved

Cookie Reading Problem in a PopUp Window

Posted on 2009-05-12
11
189 Views
Last Modified: 2012-06-27
HI Folks,

I am setting a login Cookie which stores fine. But I am trying to read the same cookie in a PopUp window within the same browser session.

I am unable to do that. Any Ideas on how to pass the cookie value to a popup window within the same browser session.

Thanks

RG
Main Browser Window
	Response.Cookies ("Cusername") = Request.Form("login")
		
	Response.Cookies ("Cusername").Expires = dateadd("H",1,now) 
        Response.Redirect("default.asp") ' Go to the main page 
 
From the PopUp Window
 
vUserName = Request.Cookies("Cusername") ' Returns Blank

Open in new window

0
Comment
Question by:rgarimella
  • 7
  • 4
11 Comments
 
LVL 30

Expert Comment

by:Wayne Barron
ID: 24365180
try this (This is what I use)

<%
' name of the cookie in example is called: Carrzkiss
strUserName = Request.Cookies("Carrzkiss")("Cusername")
If Request.Cookies("Carrzkiss")("Cusername") = "" Then
      Response.Redirect"login/index.asp?Message=You_are_Not_Logged_In"
End If
%>

Carrzkiss

0
 
LVL 30

Expert Comment

by:Wayne Barron
ID: 24365198
Is the name of your cookie    cusername?
Then that would change this to:
User = Being the name of the user logged in.

<%
' name of the cookie in example is called: Carrzkiss
strUserName = Request.Cookies("Carrzkiss")("User")
If Request.Cookies("Carrzkiss")("User") = "" Then
      Response.Redirect"login/index.asp?Message=You_are_Not_Logged_In"
End If
%>

Carrzkiss
0
 

Author Comment

by:rgarimella
ID: 24365319
Hi,

I dont have problems logging in. The problem is reading the value of  Cookie "Cusername" from a popup window, within the same browser session.

The Cookie is setting fine, but unable to read from popup window
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 30

Expert Comment

by:Wayne Barron
ID: 24365442
do this
<%
strUserName = Request.Cookies("Carrzkiss")("User")
%>

<%-strUserName%>
0
 
LVL 30

Expert Comment

by:Wayne Barron
ID: 24365460
make sure that you are also reading the file that "READS" the cookie.
Make sure that it is an <!--#include file="cookie-reader.asp"-->
If you are not reading the file within' the popup then it would explain as to why it is not reading it.

Popup Window or no Popup window.
It will still read the cookie as long as all refrences are made properly

Good Luck
Carrzkiss
0
 

Author Comment

by:rgarimella
ID: 24365501
Yes,

I did this strUserName = Request.Cookies("Carrzkiss")("User")

But still returns blank

But if I call the page directly inside a browser window instead of a Popup it shows the correct value

0
 

Author Comment

by:rgarimella
ID: 24365527
Could you explain a little bit  about

Make sure that it is an <!--#include file="cookie-reader.asp"-->

Right now I am directly reading the cookie value from a popup
0
 
LVL 30

Expert Comment

by:Wayne Barron
ID: 24365712
can you make me up a demo of what you are doing?
This way I can have a look at it to see where the issue is?
0
 

Author Comment

by:rgarimella
ID: 24365772
I have 3 files,

login_db.asp (cookie is set fine)

Response.Cookies("ckLogin")("Cusername") = Request.Form("login")

2nd
I have a html file which has a button for window.open

which opens the 3rd file add.asp which has to read the cookie

if I directly open add.asp the cookie is read fine, but when I open from the HTML file in a poup window the cookie is not read

vUserName = Request.Cookies ("ckLogin")("Cusername") ' Returns Blank
0
 
LVL 30

Accepted Solution

by:
Wayne Barron earned 500 total points
ID: 24370712
I just ran a test with a Popup Window using the code that I supplied for you above and it worked without any issue.

This is the code from my Demo Cookie Membership Login Demo that I have up here on EE

(This works without an issue)

Carrzkiss
IsLoggedIn.asp
=======================
<%
strUserName = Request.Cookies("carrzkissCookieDemo")("User")
If strUserName = "" Then
	Response.Redirect"login.asp?Message=You_are_Not_Logged_In"
End If
%>
 
============
in the popup window
<!--#inlcude file="IsLoggedIn.asp"-->
 
Display
<%=strUserName%>

Open in new window

0
 
LVL 30

Expert Comment

by:Wayne Barron
ID: 24379896
did all work out?
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

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…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

777 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