System.Net.Cookie和System.Web.HttpCookie有什么区别?

时间:2021-08-24 15:13:00

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

我获得了一个HTTPCookie,但需要一个Net.Cookie。它们只是你可以重铸的东西,或者我将如何去做?

1 个解决方案

#1


10  

Actually you have two questions:

其实你有两个问题:

  1. Difference between System.Web.HttpCookie and System.Net.Cookie
  2. System.Web.HttpCookie和System.Net.Cookie之间的区别

  3. How to convert from HTTPCookie to a Cookie.
  4. 如何转换HTTPCookie至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.

第1部分)这个问题真的很有意思,我还在想为什么有两个看起来很相似的类,我最初的想法是System.Web.HttpCookie继承了System.Net.Cookie,但这不是真的直接从Object继承因此它们是不同的类,但属性匹配很多,所以这给第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
System.Net.Cookie和System.Web.HttpCookie有什么区别?

第2部分)我认为理论上可以将一个转换为另一个,因为如果你以正确的方式填充它们,它们只是对象,这里我比较了两个类时的一些分析。单击以在新选项卡中打开以放大

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

更新:System.Web用于基于服务器的应用程序,System.Net可用于基于客户端的应用程序。

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. 编写一个可以将一个对象转换为另一个对象的方法或静态类,我没有检查所有这些对象,但是名称匹配的属性,签名也匹配。

  3. 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.
  4. 在另一个对象中不存在的属性可以填充某些常量或您知道的值与端口号等方案匹配。

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

一些链接这篇文章有一些相关的代码

#1


10  

Actually you have two questions:

其实你有两个问题:

  1. Difference between System.Web.HttpCookie and System.Net.Cookie
  2. System.Web.HttpCookie和System.Net.Cookie之间的区别

  3. How to convert from HTTPCookie to a Cookie.
  4. 如何转换HTTPCookie至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.

第1部分)这个问题真的很有意思,我还在想为什么有两个看起来很相似的类,我最初的想法是System.Web.HttpCookie继承了System.Net.Cookie,但这不是真的直接从Object继承因此它们是不同的类,但属性匹配很多,所以这给第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
System.Net.Cookie和System.Web.HttpCookie有什么区别?

第2部分)我认为理论上可以将一个转换为另一个,因为如果你以正确的方式填充它们,它们只是对象,这里我比较了两个类时的一些分析。单击以在新选项卡中打开以放大

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

更新:System.Web用于基于服务器的应用程序,System.Net可用于基于客户端的应用程序。

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. 编写一个可以将一个对象转换为另一个对象的方法或静态类,我没有检查所有这些对象,但是名称匹配的属性,签名也匹配。

  3. 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.
  4. 在另一个对象中不存在的属性可以填充某些常量或您知道的值与端口号等方案匹配。

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

一些链接这篇文章有一些相关的代码