?
Solved

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

Posted on 2016-08-20
3
Medium Priority
?
137 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 1000 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 84

Assisted Solution

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

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 500 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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…
Suggested Courses
Course of the Month15 days, 15 hours left to enroll

850 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