473,386 Members | 1,795 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,386 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 2204

<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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.