I am writing an extension for IE using C# and Windows Forms / BHO Objects. I need to create a cookie which I can use to access information from other classes / forms in the app.
The various methods for creating cookies all seem to be related to ASP.NET and using the Http Response Filter, which do not help me here. I am not sure that I even need a session for what I am trying to accomplish, I just need to be able to create the cookie, access the information from the application, and then p开发者_JS百科urge when needed. Thanks!
Sessions and cookies are web technology. You probably won't need to have that in your Windows application. Instead you can use a static class.
internal static class MySharedInfo {
/* static proerties and whatever you need */
}
This is just one way. A really suitable method depends on what you actually want to achieve.
I also used similar code for our application cookies.
HttpWebRequest runTest;
//...do login request
//get cookies from response
CookieContainer myContainer = new CookieContainer();
for (int i = 0; i < Response.Cookies.Count; i++)
{
HttpCookie http_cookie = Request.Cookies[i];
Cookie cookie = new Cookie(http_cookie.Name, http_cookie.Value, http_cookie.Path);
myContainer.Add(new Uri(Request.Url.ToString()), cookie);
}
//later:
HttpWebRequest request =
(HttpWebRequest)WebRequest.Create("http://www.url.com/foobar");
request.CookieContainer = myContainer;
精彩评论