TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Mark
NA
29
0
Getting a cookie from a web project into a WinForm
May 2 2018 7:42 AM
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
Reply
Answers (
6
)
New Project in Visual Studio giving Error -
Dynamically load c# code from mssql databade