c# - 查看源代码中的viewsate ["x"]和__viewstate有什么区别?

标签 c# asp.net .net

我想了解 View 源中viewsate["x"] 和 __viewstate 之间的区别

在查看源页面中,隐藏控件中有 View 状态,例如:

<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="dO3F9exemRdHoXxGHr"/>

但在 C# 中我可以创建 View 状态,例如:

viewstate["x"]="Hi";

那么有什么区别???

以及字符串“Hi”保存在哪里?在这隐藏的地方还是哪里?

最佳答案

When a page is rendered, it serializes its view state into a base-64 encoded string using the LosFormatter class and (by default) stores it in a hidden form field. On postback, the hidden form field is retrieved and deserialized back into the view state's object representation, which is then used to restore the state of the controls in the control hierarchy.

这意味着它保存在这个隐藏字段中,但它是编码的。阅读 MSDN article了解更多信息。这句话来自6.解析 View 状态

如果您有兴趣,可以解析 ViewState 并查看他的“真实值”。你可以搜索 View 状态解析器,经过研究我发现了这个Website

关于c# - 查看源代码中的viewsate ["x"]和__viewstate有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27871585/

相关文章:

asp.net - 就地处理(无重定向)401 未经授权?

c# - 注销后如何防止浏览器后退按钮?

c# - == 与 C# 中的等于

.net - 具有硬阈值的队列结构

c# - 仅将文件夹名称获取到数据表中

c# - 在 C# 中,是否有通用方法将 DBSet 传递给方法?

asp.net - 我们可以在按钮单击事件发生后更改分配给 div 的 css 吗?

c# - 声明泛型类时 new() 的目的是什么?

c# - 使用 while 循环将项目添加到列表框时,程序失败

c# - 在 WPF 中禁用键