C# School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a C# Expert!

Join 300,497 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 1,854 people online right now. Registration is fast and FREE... Join Now!




HttpCookie Problem.

 

HttpCookie Problem.

cel09

3 Jul, 2009 - 08:14 AM
Post #1

New D.I.C Head
*

Joined: 3 Jul, 2009
Posts: 24

Hello, I'm new in this forum.

I want to make a web request with cookies.
This is my code:

CODE

HttpCookie cookie = new HttpCookie();
cookie.Value = "43546579";
Response.Cookies.Add(cookie);


Is this correct way to do this ? And I'm getting error: "The type or namespace name 'HttpCookie' could not be found". - Is System.Web incorrect ?

Thanks.

User is offlineProfile CardPM
+Quote Post


PsychoCoder

RE: HttpCookie Problem.

3 Jul, 2009 - 08:19 AM
Post #2

Dyslexics Untie!
Group Icon

Joined: 26 Jul, 2007
Posts: 14,714



Thanked: 501 times
Dream Kudos: 11450
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net, jQuery

My Contributions
Yes the HttpCookie Class is part of the System.Web Namespace (not sure why you're getting this error). Have you added this to your class

CODE

using System.Web


To make a coookie should look something like this

CODE

HttpCookie cookie = new HttpCookie("YourCookieName");
cookie.Value = "43546579";
Response.Cookies.Add(cookie);

User is offlineProfile CardPM
+Quote Post

cel09

RE: HttpCookie Problem.

3 Jul, 2009 - 08:42 AM
Post #3

New D.I.C Head
*

Joined: 3 Jul, 2009
Posts: 24

Yes, I have using System.Web, and I used:
CODE
HttpCookie cookie = new HttpCookie("YourCookieName");


But I'm still getting same error.


User is offlineProfile CardPM
+Quote Post

JackOfAllTrades

RE: HttpCookie Problem.

3 Jul, 2009 - 02:19 PM
Post #4

I exist to Google your problems.
Group Icon

Joined: 23 Aug, 2008
Posts: 4,948



Thanked: 424 times
Dream Kudos: 50
Expert In: Being annoyed with lazy people.

My Contributions
Have you added a reference to System.Web in your project?
User is offlineProfile CardPM
+Quote Post

cel09

RE: HttpCookie Problem.

3 Jul, 2009 - 11:01 PM
Post #5

New D.I.C Head
*

Joined: 3 Jul, 2009
Posts: 24

QUOTE(JackOfAllTrades @ 3 Jul, 2009 - 02:19 PM) *

Have you added a reference to System.Web in your project?

Yes.
User is offlineProfile CardPM
+Quote Post

cel09

RE: HttpCookie Problem.

5 Jul, 2009 - 12:38 PM
Post #6

New D.I.C Head
*

Joined: 3 Jul, 2009
Posts: 24

I think I'm using it in wrong way... Can this be used in asp only ?

I want to make a simple webrequest:

CODE
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("url");

            HttpWebResponse response;
            Stream dataStream;
            StreamReader reader;

          
                response = (HttpWebResponse)request.GetResponse();
                dataStream = response.GetResponseStream();
                reader = new StreamReader(dataStream);


Like this, and the page that I'm trying to connect checks if I have certain cookie, I want this cookie to be made available for that page.

Thanks.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/8/09 04:55AM

Live C# Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month