9

I obtain a HTTPCookie, but need a Net.Cookie. Are they just something you can recast, or how would i go about it?

Fallenreaper
  • 8,518
  • 10
  • 53
  • 107
  • Poss. duplicate: http://stackoverflow.com/questions/1779410/c-sharp-sharp-the-difference-between-httpcookie-and-cookie – David W Oct 26 '12 at 19:27
  • How would i be able to convert 1 to another though? That isnt covered, and it seems to be what I need done. – Fallenreaper Oct 26 '12 at 19:49
  • survey says: http://stackoverflow.com/questions/1214387/sending-cookies-using-httpcookiecollection-and-cookiecontainer is how you go between the 2 – Fallenreaper Oct 26 '12 at 19:56

1 Answers1

12

Actually you have two questions:

  1. Difference between System.Web.HttpCookie and System.Net.Cookie
  2. How to convert from HTTPCookie to a Cookie.

Part 1)
This question is really interesting ,I'm still thinking why there are two classes which looks pretty same ,My initial thought was System.Web.HttpCookie inherits System.Net.Cookie but this isn't true both directly inherit from Object so they are distinct classes ,but the properties matches a lot ,so this gives a hope for the solution of part 2.

Part 2)
I think its possible to convert one into another theoretically since both are just objects if you populate them the right way it will work , here a little analysis when I compared the two classes.

Click to open in new tab to enlarge
Click to open in new tab to enlarge

Update: The System.Web is made to be used in server-based apps and System.Net can be used for client based apps.

Some Thoughts:

  1. Write a method or a static class which can convert one object into another, I haven't check all of them but properties whose names match, there signature also matches.
  2. Properties which don't exists in the another object you can stuff some constant or a value which you know matches the scenario like Port number.

Good luck ,let me know how you came up with the final solution ,post the code or link.

Some Links this post has some related code

Community
  • 1
  • 1
Owais Qureshi
  • 4,078
  • 5
  • 36
  • 58
  • 1
    Relevant posts on this topic https://social.msdn.microsoft.com/Forums/office/en-US/9062e220-ebaa-4c61-a716-13fcdb2ecedb/how-to-convert-systemwebhttpcookie-to-systemnetcookie-?forum=csharpgeneral – Owais Qureshi Feb 13 '17 at 03:12