472,952 Members | 2,209 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

ASP cookie reading using C#

I have a C# utility that runs in ASP website. when user logs in the
ASP code writes the cookie. I am unable to read it in C# code.

I am using Request.Cookies["cookiename"].Value.ToString()
I can read the same cookie in ASP code.
If I say Request.Cookies("CookieName") in ASP that works fine..
Jun 27 '08 #1
3 2192

<ic********@gmail.comwrote in message
news:20**********************************@n1g2000p rb.googlegroups.com...
>I have a C# utility that runs in ASP website. when user logs in the
ASP code writes the cookie. I am unable to read it in C# code.

I am using Request.Cookies["cookiename"].Value.ToString()
I can read the same cookie in ASP code.
If I say Request.Cookies("CookieName") in ASP that works fine..
You should post to ms.public.dotnet.framework.aspnet.

Jun 27 '08 #2
A page with the below code reads cookies stored on a user's browser.

Hope this may provide solution/idea for your query.
----------------------------------------------------
<%@ language="C#" %>
<script runat="server">
void ReadClicked(Object Sender, EventArgs e)
{
//Get the cookie name the user entered
String strCookieName = NameField.Text;
//Grab the cookie
HttpCookie cookie = Request.Cookies[strCookieName];
//Check to make sure the cookie exists
if (null == cookie)
{
Response.Write("Cookie not found. <br><hr>");
}
else
{
//Write the cookie value
String strCookieValue = cookie.Value.ToString();
Response.Write("The " + strCookieName + " cookie contains: <b>" + strCookieValue + "</b><br><hr>");
}
}
</script>
<html>
<body>
Use the button below to read a cookie<br>
<form runat="server">
Cookie Name <asp:textbox id="NameField" runat="server" />
<asp:button text="ReadCookie" onclick="ReadClicked" runat="server" />
</form>
<a href="writecookies.aspx">Write Cookies</a>
</body>
</html>
----------------------------------------------------

You can store multiple strings in a cookie using the HttpCookie class. This class have few advanced properties.
Jun 27 '08 #3
Reading a Cookie:

HttpCookie myCookie = new HttpCookie("MyTestCookie");
myCookie = Request.Cookies["MyTestCookie"];

// Read the cookie information and display it.
if (myCookie != null)
Response.Write("<p>"+ myCookie.Name + "<p>"+ myCookie.Value);
else
Response.Write("not found");
Refere this link for more info :
http://www.csharphelp.com/archives/archive179.html
Jun 27 '08 #4

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

Similar topics

0
by: Serge | last post by:
Good Day Folks I'm using the following code when creating, reading, and removing a cookies. <% ' writing cookie Response.cookies("OracleLogin")("p_userid")="fcs_system"...
0
by: G R | last post by:
Hi Here is the STEPS/METHOD my service provider sends the calling customer numbers captured : Export Method - HTTP 1. The partner provides Who’s Calling with a URL address to direct the data...
3
by: R. de Vos | last post by:
Hi all you experts, I have a 'small' problem In a mdb I have a column called "PLACE" its value type = text rowsourcetype=list with values Rowsource = HOME;SCHOOL;STATION What I would like...
3
by: georges the man | last post by:
how do i read from a text file using fread
1
by: 4site | last post by:
Hi all, this is probably stupidly easy but I'm struggling. I am trying to understand why cookies only appear to be readable when a web page is retrieved by *typing the url into the browser's...
3
by: ambrish | last post by:
How can I read any text(PDF/Doc/PPT/rtf/etc.) file using PHP. Ambrish
1
by: shaahid786 | last post by:
hallo, Plz tell me how can i read an Excell File using php code. its very urgent if sombody is on line plz tell me fast.coz i have to work on that. i have already search on diffrent sites...
4
by: boonboy28 | last post by:
I have a BS microcontroller sending data over the serial port to a pc with php. the data is indeed sent as it is displayed within the terminal window. So I have sent and received data over the serial...
1
by: artic | last post by:
Hi all.. I am currently doing a project on Card Reading using Java. I need one help, which package is best to read the card in java?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...

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.