Solved

Cookie Reading Problem in a PopUp Window

Posted on 2009-05-12
11
185 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
 
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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 demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

707 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

15 Experts available now in Live!

Get 1:1 Help Now