开发者

Create a cookie using Windows Forms C# Application?

开发者 https://www.devze.com 2023-04-11 04:19 出处:网络
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.

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;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号