Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to set a cookie in C# from .NET Compact Framework?

4 views
Skip to first unread message

N. Anand

unread,
Feb 3, 2003, 12:40:23 AM2/3/03
to
I am using version 1.0 of .NET framework (because in my 2003 beta
installation the debugger does not work properly). I have to set a
cookie in C# and send it to the server. The following code throws an
exception and fails to set the cookie properly. Could someone tell me
how to set the cookie from C#? The code is as follows :
------------------------------------------------------
urlCon = (System.Net.HttpWebRequest)
System.Net.HttpWebRequest.Create(url);
...
SupportClass.URLConnectionSupport.SetRequestProperty(urlCon, "cookie",
sessionId); // throws an exception
...
System.Net.HttpWebResponse httpWebResponse =
(System.Net.HttpWebResponse) urlCon.GetResponse();
------------------------------------------------------
public static void SetRequestProperty(System.Net.HttpWebRequest
connection, System.String key, System.String keyValue)
{
if (connection.HaveResponse)
throw new System.Exception("Already connected");
connection.Headers.Add(key, keyValue);
}
------------------------------------------------------
The CookieContainer property doesn't seem to be supported by my
version of the compact framework.

Thanks and Regards,
N. Anand

Alex Yakhnin [eMVP]

unread,
Feb 3, 2003, 9:16:11 AM2/3/03
to

You can set the cookies on the request in CF like this:

//============================================
HttpWebRequest request = (HttpWebRequest
HttpWebRequest.Create(url);

request.Headers.Add("Cookie:" + "somecookie");
//============================================

HTH... Alex
--
Alex Yakhnin, eMVP
IntelliProg, Inc.
http://www.intelliprog.com


>-----Original Message-----
>I am using version 1.0 of .NET framework (because in my
2003 beta
>installation the debugger does not work properly). I have
to set a
>cookie in C# and send it to the server. The following
code throws an
>exception and fails to set the cookie properly. Could
someone tell me
>how to set the cookie from C#? The code is as follows :
>------------------------------------------------------
>urlCon = (System.Net.HttpWebRequest)
>System.Net.HttpWebRequest.Create(url);

>....
>SupportClass.URLConnectionSupport.SetRequestProperty


(urlCon, "cookie",
>sessionId); // throws an exception

>....


>System.Net.HttpWebResponse httpWebResponse =
>(System.Net.HttpWebResponse) urlCon.GetResponse();
>------------------------------------------------------
>public static void SetRequestProperty
(System.Net.HttpWebRequest
>connection, System.String key, System.String keyValue)
>{
>if (connection.HaveResponse)
> throw new System.Exception("Already connected");
>connection.Headers.Add(key, keyValue);
>}
>------------------------------------------------------
>The CookieContainer property doesn't seem to be supported
by my
>version of the compact framework.
>
>Thanks and Regards,
>N. Anand

>.
>

Anand Narayana Rao

unread,
Feb 4, 2003, 12:22:48 AM2/4/03
to
I have tried setting the cookie this way but it throws an
ArgumentException and does not set the cookie. It still does not work!

Thanks and Regards,
N. Anand

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Robert Levy [MVP]

unread,
Feb 4, 2003, 1:36:11 AM2/4/03
to
Are you using the VS.NET 2003 Final Beta?

--
Robert Levy
Microsoft MVP - Mobile Devices, Smartphone

"Anand Narayana Rao" <anan...@mindtree.com> wrote in message
news:uApg11AzCHA.2684@TK2MSFTNGP11

Anand Narayana Rao

unread,
Feb 4, 2003, 1:52:42 AM2/4/03
to
No, I am not using the 2003 beta because the debugger does not seem to
work in that version. I need the debugger badly.
The version I am using is as follows :

Microsoft Development Environment 2002 version 7.0.9466
Microsoft .NET Framework 1.0 version 1.0.3705
Microsoft Smart Device Extensions for Visual Studio .NET version
7.00.2098

Robert Levy [MVP]

unread,
Feb 4, 2003, 2:33:48 AM2/4/03
to
Well that's likely to explain why code that works for the rest of us doesn't
work for you. Many bugs have been fixed and features added since Beta 1.

--
Robert Levy
Microsoft MVP - Mobile Devices, Smartphone

"Anand Narayana Rao" <anan...@mindtree.com> wrote in message

news:#Rs2EoBzCHA.2512@TK2MSFTNGP11

0 new messages