Solved

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

Posted on 2016-08-20
3
85 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 80

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

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.

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This article discusses how to create an extensible mechanism for linked drop downs.
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…

679 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