Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello every one

I need to read cookie from my windows application form local system i know the cookie name just i need to get its value . so how can i get it . I use adding web dll to my application . Then in internet it show to take an httpcookie object reference
so i followed like this

C#
HttpCookie obj = new HttpCookie("T"); 
HttpWebRequest request = new HttpWebRequest();
HttpWebResponse res = new HttpWebResponse();


even i tried to use a cookie count like this

C#
HttpCookieCollection colect = new HttpCookieCollection();
int a= colect.Count;


but it s showing 0 ,So how can i read the value inside the cookie

Advance thanks
Arun
Posted
Updated 12-Oct-11 22:46pm
v2

you can write a simple ASP.NET app to try and read that cookie :) just one page app with one button and a textbox or whatever. Also have a look at this, you may be running into security issues:

http://msdn.microsoft.com/en-us/library/aa289495%28v=vs.71%29.aspx[^]


Cheers...
 
Share this answer
 
In general, it can't be done. Cookies stored on your local machine are stored in different places depending on what application did the browsing – websites you looked at in IE and Chrome will have cookies in two different places. I think that the Framework acts as a browser, so if you use HttpWebRequest you will have the cookies sent by .Net apps on your computer, but that might not be the case, it might be keyed by process.

You need to explain what you're actually trying to do, I suspect you are misunderstanding something about cookie storage or client/server issues.
 
Share this answer
 
Comments
arunrv 13-Oct-11 7:20am    
actual i want to have a user link from web application to windows application . I m going to use IE its self .
Now the detail
When a user logs in At a login page a cookie s created at a client machine . Then in my web application i m having a option to run a windows application . Now to run that window application i need the user name . So at this time i m going to fetch the user name from cookie ,That's y i want to kno to read the cookie in windows application ......
BobJanova 13-Oct-11 8:57am    
There are a number of things wrong with this model:
- A web application doesn't use one browser, it is deployed on the web - the user could use any browser.
- You can't put a link on a web page that will open an application locally (security restriction) – which is a good thing, imagine if websites could open whatever you wanted!
- Why would you want to switch from a web version to a full app version? If you are providing both interfaces, and the user wants to use the app for more extensive editing, why not just tell them to start with (and log in through) the desktop application? Alternatively, make the web application fully functional (should be possible with AJAX/DHTML, and if not, you have Flash/Silverlight/Java for active components).
using System.Net;
using System;
namespace Examples.System.Net.Cookies
{
// This example is run at the command line.
// Specify one argument: the name of the host to
// send the request to.
// If the request is sucessful, the example displays the contents of the cookies
// returned by the host.

public class CookieExample
{
public static void Main(string[] args)
{
if (args == null || args.Length != 1)
{
Console.WriteLine("Specify the URL to receive the request.");
Environment.Exit(1);
}
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(args[0]);
request.CookieContainer = new CookieContainer();

HttpWebResponse response = (HttpWebResponse) request.GetResponse();
response.Cookies = request.CookieContainer.GetCookies(request.RequestUri);


// Print the properties of each cookie.
foreach (Cookie cook in response.Cookies)
{
Console.WriteLine("Cookie:");
Console.WriteLine("{0} = {1}", cook.Name, cook.Value);
Console.WriteLine("Domain: {0}", cook.Domain);
Console.WriteLine("Path: {0}", cook.Path);
Console.WriteLine("Port: {0}", cook.Port);
Console.WriteLine("Secure: {0}", cook.Secure);

Console.WriteLine("When issued: {0}", cook.TimeStamp);
Console.WriteLine("Expires: {0} (expired? {1})",
cook.Expires, cook.Expired);
Console.WriteLine("Don't save: {0}", cook.Discard);
Console.WriteLine("Comment: {0}", cook.Comment);
Console.WriteLine("Uri for comments: {0}", cook.CommentUri);
Console.WriteLine("Version: RFC {0}" , cook.Version == 1 ? "2109" : "2965");

// Show the string representation of the cookie.
Console.WriteLine ("String: {0}", cook.ToString());
}
}
}
}
may this code help you
thanku
 
Share this answer
 
Comments
arunrv 14-Oct-11 0:10am    
I have all ready tried it

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900