Solved

Can a .NET page read a cookie written by an html page?

Posted on 2016-08-20
3
65 Views
Last Modified: 2016-08-20
I am writing a cookie via javascript from within a basic HTML page, to indicate that the user is logged in.
There is another page on the site that is written in ASP.NET, which needs to know whether the user is logged in.
Is it possible for an ASP.NET page to read a cookie written by an HTML page? Or can .NET pages only read cookies written by other .NET pages?
0
Comment
Question by:rascal
3 Comments
 
LVL 9

Accepted Solution

by:
bas2754 earned 250 total points
ID: 41763841
Old post from here outlines the steps:
----------------
http://forums.asp.net/t/1250217.aspx?cookie+writing+in+javascript+and+reading+in+asp+net

Summary of the answer from that page:
-----------------------
            Dim UserResolution As String
            If Request.Cookies("Screen") IsNot Nothing Then
                Dim TheCookie As HttpCookie = Request.Cookies("Screen")
                UserResolution = Server.HtmlEncode(TheCookie.Value)
            Else
                UserResolution = "NA"
            End If

Open in new window


Basically you just substitue the name of your cookie for the "Screen" variable written above and it should work for you.  Read through the page for more info, but I do know it works as I have done it as well, I just don't have access to the code right now to give you the examples I have done.
0
 
LVL 79

Assisted Solution

by:David Johnson, CD, MVP
David Johnson, CD, MVP earned 125 total points
ID: 41763855
A qualified yes.. getting the details right is the hard part.
0
 
LVL 83

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 125 total points
ID: 41763878
In cookies, the domain name must be an exact text match.  'www.domain.com' is Not the same as 'domain.com' in cookies.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

867 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

16 Experts available now in Live!

Get 1:1 Help Now