比较 Viewstate 和 SessionState

发布于 2024-09-08 16:40:39 字数 325 浏览 0 评论 0原文

我将 ViewState["zzz"] 和 Session["zzz"] 设置为同一字符串。

当我使用 == 进行比较时,我得到错误。

当我执行 ViewState["zzz"].Equals(Session["zzz"]) 时,我得到了正确的结果。

在调试器中,它们的值显示相同的字符串,当我这样做时,

? ViewState["zzz"] == Session["zzz"]

我得到错误。

我认为 ViewState StateBag Item 默认为设置值,Session Item 也默认为该值?

I set ViewState["zzz"] and Session["zzz"] to the same string.

When I compare using == I get false.

When I do ViewState["zzz"].Equals(Session["zzz"]), I get true.

In the debugger, both their values show the same string, and when I do

? ViewState["zzz"] == Session["zzz"]

I get false.

I thought the ViewState StateBag Item defaults to the set value and the Session Item defaults to the value as well?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

骑趴 2024-09-15 16:40:39

由于 ViewState 和 Session 都存储对象,因此在比较之前必须将它们转换为字符串,否则您将得到引用比较,而不是调用重载字符串运算符 == 。

(string) ViewState["zzz"] == (string) Session["zzz"]

Since both ViewState and Session are storing objects, you must cast them to string before comparing, otherwise you'll get a reference comparison instead of the overload string operator == called.

(string) ViewState["zzz"] == (string) Session["zzz"]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文