473,408 Members | 1,747 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Getting cookies of previous page

Hi !

I want to know the cookie value that was set in the previous page.

Initially in my page in project B I used

HttpCookie cookie = Request.Cookies.Get(somefile.COOKIE_NAME);

where cookie name is set using web.config. As a result when I call
this page of project B from some page in Project A, I get the cookie
of project B. But I want to get the cookie in the Request.Cookie from
the page in Project A. How do i do that ?

Thanks!

Apr 11 '07 #1
5 2374
"Zeba" <co******@gmail.comwrote in message
news:11**********************@b75g2000hsg.googlegr oups.com...
Initially in my page in project B I used

HttpCookie cookie = Request.Cookies.Get(somefile.COOKIE_NAME);

where cookie name is set using web.config. As a result when I call
this page of project B from some page in Project A, I get the cookie
of project B. But I want to get the cookie in the Request.Cookie from
the page in Project A. How do i do that ?
Request.Cookies["CookieName"] will allways return to you the cookie
regardless of the page that set it, on the condition that the browser is
sending to you that cookie in the Request. The browser will only send
cookies when the request is going to the same domain (such as
www.mydomain.com) that originally sent that cookie in its Response. So, as
long projectA and projectB both have a URL below the same domain, you
shouldn't have any problem getting the cookie.

Apr 11 '07 #2
Actually, i retrieve the cookie name from
myUXE.Lib.Web.AppConfigCookie.COOKIE_NAME which is actually provided
to me as .dll files to include in the project. This .dll file is
available in both the projects A and B.

Project A sets its cookie name in its web.config and Project B in its
web.config. So when in Project B's page I give
HttpCookie cookie =
Request.Cookies.Get(myUXE.Lib.Web.AppConfigCookie. COOKIE_NAME);
it actually accesses the cookie with the cookie name set by Project B.
How do I get the cookie name set by Project A ?

Thanks !
Request.Cookies["CookieName"] will allways return to you the cookie
regardless of the page that set it, on the condition that the browser is
sending to you that cookie in the Request. The browser will only send
cookies when the request is going to the same domain (such aswww.mydomain.com) that originally sent that cookie in its Response. So, as
long projectA and projectB both have a URL below the same domain, you
shouldn't have any problem getting the cookie.

Apr 11 '07 #3

"Zeba" <co******@gmail.comwrote in message
news:11**********************@q75g2000hsh.googlegr oups.com...
Actually, i retrieve the cookie name from
myUXE.Lib.Web.AppConfigCookie.COOKIE_NAME which is actually provided
to me as .dll files to include in the project. This .dll file is
available in both the projects A and B.

Project A sets its cookie name in its web.config and Project B in its
web.config. So when in Project B's page I give
HttpCookie cookie =
Request.Cookies.Get(myUXE.Lib.Web.AppConfigCookie. COOKIE_NAME);
it actually accesses the cookie with the cookie name set by Project B.
How do I get the cookie name set by Project A ?
I misunderstood the original question. I thought that the problem was
recovering the cookie itself, when your problem is actually finding out the
name of the cookie.
If I have understood what you are doing, you are calling a DLL that
retrieves the name from its .config file. You want to force the DLL that is
in your project to read the .config file from another project. This is not
going to be easy if you are not allowed to modify the source code of the
DLL. The config file is set when the AppDomain that loads the DLL is
created, and in the case of a web app this is done by aspnet_wp and you
can't change its behaviour as far as I know.
I can think of some alternatives: One is to create an AppDomain, set the
config file to the config in the other project, and load the DLL inside it,
then call the dll.
Another alternative would be to create a folder below the main folder of
projectB, create a second web.config in that folder, copy into it the
relevant portion of the web.config in projectA, and run the page that needs
the cookie name in that folder. The web.config in the subfolder should take
priority over the web.config in the main folder.
A third alternative would be to write a webservice in projectA to return
the cookie name, and call that webservice from projectB.
Apr 11 '07 #4
Thanks a lot ! That was interesting. I was thinking if I could just
parse the referrer url and check the project name and thus set my
cookie name ( hard-coding ) for the time being.

But when I use something like
if (Request.UrlReferrer.ToString().Contains("http://localhost/
mySite"))
I get the error that UrlReferrer object is not instantiated.
How do I get the url of the calling page?

Thanks !

I can think of some alternatives: One is to create an AppDomain, set the
config file to the config in the other project, and load the DLL inside it,
then call the dll.
Another alternative would be to create a folder below the main folder of
projectB, create a second web.config in that folder, copy into it the
relevant portion of the web.config in projectA, and run the page that needs
the cookie name in that folder. The web.config in the subfolder should take
priority over the web.config in the main folder.
A third alternative would be to write a webservice in projectA to return
the cookie name, and call that webservice from projectB.

Apr 11 '07 #5
"Zeba" <co******@gmail.comwrote in message
news:11*********************@e65g2000hsc.googlegro ups.com...
if (Request.UrlReferrer.ToString().Contains("http://localhost/
mySite"))
I get the error that UrlReferrer object is not instantiated.
How do I get the url of the calling page?
UrlReferrer is not reliable. It only works if the browser is sending the
"Referrer" HTTP header, which is optional, so you can't depend on all
browsers sending it.
But anyway, if the browser does send it, Request.UrlReferrer should be
instantiated and should provide you with the value that you want. Where are
you executing that code? If you do it in Page_Load it should work.

Apr 11 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: windandwaves | last post by:
Hi Gurus I am basically sorry that I have to bother you about this. I am a PHP beginner and I have been studying sessions and cookies over the last few weeks. I have learned lots, but I am...
20
by: Brian Burgess | last post by:
Hi all, Anyone know if this is possible? If so, on which page would the cookie be? .. On the page calling a function defined in the include file? thanks in advance.. -BB
3
by: techie | last post by:
I am using the following to delete the contents of a cookie Response.Cookies("maincookie").expires = DateAdd("d",-2,now) Response.redirect "login.asp" If i try to alert the value of the cookie...
0
by: Amit Jamgade | last post by:
Hi, I am making use of cookies to store the Session State information through JavaScript as given below in an ASP Page. Suppose I have XYZ.asp page. The code in this page goes as shown below....
2
by: Goober | last post by:
I have an application where we have a limited number of users and a set requirement for web access. An app that I have inherited uses cookies to set certain values (i.e. what would correspond to...
0
by: Denver Developer | last post by:
I have a cookie that is set by a previous ASP page that I wish to update with the following logic. MyCookieColl = Request.Cookies; for (loop1 = 0; loop1 < MyCookieColl.Count ; loop1++) {...
1
by: Alan Silver | last post by:
Hello, I am just converting one of my pages from code-beside to code-behind. I removed all the C# and put that in a separate file (Basket.cs) and added references for all the ASP controls on the...
6
by: James MA | last post by:
I'm now writing a small program to communicate a web server to simulate a web client. I use te httpwebrequest to talk with the server, and it works find for "POST" method, however, when i test...
3
by: Victor | last post by:
I was thinking about an easy to determine if cookies are set or not in ASP. I began thinking about how the Session ID is dependent upon a cookie - right? Well, I disabled cookies in Firefox and...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.