Hi there,
I have an application which i have created. The application is a Windows based application mainly written in C# but has some different projects within it. I have a Form project and a web project
Within the web project i have created an ASP.net page which saves data typed into an input box into a cookie, i can then retrieve this data by loading it back out of the cookie as shown below:
- HttpCookie cookie = new HttpCookie("Name");
- cookie.Value = TextBox1.Text.ToString();
- cookie.Expires = DateTime.Now.AddMinutes(10);
- Response.Cookies.Add(cookie);
-
- TextBox1.Text = Request.Cookies["Name"].Value;
So my question is, in a winform created in C# how can i get hold of the cookie information? I have seen some examples of ways to do this but they are messy and are very browser dependent, like the one shown below:
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create(args[0]);
- request.CookieContainer = new CookieContainer();
-
- HttpWebResponse response = (HttpWebResponse)request.GetResponse();
- response.Cookies = request.CookieContainer.GetCookies(request.RequestUri);
-
- foreach (Cookie cook in response.Cookies)
- {
- Console.WriteLine("Cookie:{0} = {1}", cook.Name, cook.Value);
- }
Some have also said:
- Properties.Settings.Default.MySettingString = "New Value";
- Properties.Settings.Default.Save();
- ...
- string myValue = Properties.Settings.Default.MySettingString;
That would be nice as a solution, except i have two different projects and so it won't work as properies.settings are project specific.
I just need a way of passing a variable from a web project into a win forms project (within the same Visual Studio solution) for a person's name in a basic computer game, hence me trying to use a cookie, all ideas are welcomed as i am probably going a bad way of doing it. The only other way i could think of was saving to an SQL database
Many thanks,
Mark