473,503 Members | 1,710 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C# web method can't see cookies?

Hi everyone.

My web application wants to take advantage of an encrypted
authentication cookie that's provided by another application on the
same server. The cookie is visible on the client side, but when I
invoke a method on my web service no cookies are visible.

For example, here is the relevant code in an example Javascript
client:

var o = new ActiveXObject("MSXML2.XMLHTTP");
o.open("POST","http://localhost/Example/Service1.asmx",false);
o.setRequestHeader("Content-Type", "text/xml");
o.setRequestHeader("SOAPAction", "http://tempuri.org/HelloWorld");
o.setRequestHeader("Cookie", "foo=bar; baz=quux");
o.setRequestHeader("Cookie", "foo=bar; baz=quux");
o.setRequestHeader("FOO", "BAR");
var msg = "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-
instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema'
xmlns:soap='http://schemas.xmlsoap.org/soap/
envelope/'><soap:Body><HelloWorld xmlns='http://tempuri.org'></
HelloWorld></soap:Body></soap:Envelope>";
o.send(msg);
alert (o.responseXML.xml);

And here is the relevant code in the C# method it calls:

[WebMethod]
public string HelloWorld()
{
return "Hello World! There are " +
Context.Request.Cookies.Count.ToString() + " cookies! Your FOO header
is " + Context.Request.Headers["FOO"] + " but your Cookies header is "
+ Context.Request.Headers["COOKIES"];
}

What I get back in the alert message indicates zero cookies and a
completely empty Cookies header, but the FOO header comes through with
the "BAR" content. So it seems that something is stripping the Cookies
header from my request.

My multipart question: Is there some feature of the .NET Framework
that prevents cookies from coming through? Or is it the XMLHTTP client-
side object? Or am I missing the point entirely?

Please post solutions, commiseration, war stories, and pointers to
documentation. Thanks in advance.
Mark W. Schumann
Some Guy on Bridge Avenue
Jun 27 '08 #1
2 3675
da****@underflap.com wrote in news:2001dd32-a9af-472f-a1c2-
34**********@a23g2000hsc.googlegroups.com:
My web application wants to take advantage of an encrypted
authentication cookie that's provided by another application on the
same server. The cookie is visible on the client side, but when I
invoke a method on my web service no cookies are visible.
Have you looked at building RESTful Web services instead? Seems like
you're trying to connect to the web service using a lgnague that does
not natively support web services... in which case RESTful style
webservices would be better.

But in anycase, I think for cookies to work in webservices, you need to
enable session statefulness. Not good if you're planning for
scalability.

Instead - use SOAP headers to transfer this sort of information (instead
of cookies).

--
sp**********@rogers.com (Do not e-mail)
Jun 27 '08 #2
On Apr 19, 8:20 pm, Spam Catcher <spamhoney...@rogers.comwrote:
dad...@underflap.com wrote in news:2001dd32-a9af-472f-a1c2-
Have you looked at building RESTful Web services instead? Seems like
you're trying to connect to the web service using a lgnague that does
not natively support web services... in which case RESTful style
webservices would be better.
The problem is that I'm being given an authentication cookie. That's
what
the environment supports.

But in anycase, I think for cookies to work in webservices, you need to
enable session statefulness. Not good if you're planning for
scalability.
But I don't need my service to manage a session--it just needs to see
a
cookie that I know is in the request headers.

Instead - use SOAP headers to transfer this sort of information (instead
of cookies).
That's the crazy thing. Other headers (such as the fake "Foo" header
in
my posted example) come through fine. It's just "Cookie" that gets
eaten
along the way. If I call it "Foo" or "CookieX" or whatever, that
works.

My point is that it looks as though something in the .NET Framework
removes "Cookie" headers, and only "Cookie" headers, from incoming
requests to a Web Service. I'm trying to figure out why this is
happening.

Thanks.
Jun 27 '08 #3

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

Similar topics

3
2365
by: Roger Lord | last post by:
I'm starting a session with session_start. That works fine. I can see the $_SESSION variables from other php pages. However, when I go to an external website and call one of the php pages from a...
24
2823
by: el_roachmeister | last post by:
Is there a way to make a text link post to a form without passing all the parameters in the url? The urls tend to get very long and messy. I often wonder if there is a limit to how long they can...
7
29728
by: Eric | last post by:
I am certain the answer will be 'NO', but I wanted to ask anyway just incase I have missed something. Everyone knows that one pass data to a page in an anchor tag by using the GET Method: <a...
1
2244
by: Tommy | last post by:
I want to encrypt the values of my cookies. I found out that I could create a FormsAuthenticationTicket, and use the FormsAuthentication.Encrypt method to encrypt the cookie. However, I do not...
6
8834
by: Stephane | last post by:
Hi, I have a login page where if the user wants his access codes to be saved are set into a cookie. In the logout page, I want to delete those cookies. I tried this and this is not working at...
6
8736
by: James MA | last post by:
I'm now writing a small program to communicate a web server to simulate a web client. I use te httpwebrequest to talk with the server, and it works find for "POST" method, however, when i test...
2
1373
by: Kevin Blount | last post by:
I have a situation where I think I'm calling a method too quickly, but I'm not sure a) how to prove that theory and b) slow it down if I'm right. Here's the code: CODEFILE.ASPX.CS public void...
10
1640
by: _Who | last post by:
Given Request.Cookies and Response.Cookies in asp.net is there any reason to ever use javascript or any other method to use cookies? Thanks
6
1377
by: jake | last post by:
I think I may why this is happening but I am a little fuzzy as to what the solution should be as I am somewhat new to all of this. My simplified code that generates the error is: public static...
0
7199
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
7074
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
7322
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...
0
7451
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5572
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3161
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3150
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1501
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.