在 ASP.NET 应用程序中将 Session 对象的代码放置在何处

发布于 2024-09-15 06:32:56 字数 212 浏览 4 评论 0原文

我在尝试使用会话状态服务器而不是 InProd 时遇到序列化错误。但是,我无法弄清楚是什么导致了会话中的错误。我得到了一些代码添加到页面以循环会话对象并确定其中的每个项目是否可序列化。我的问题是我不知道将代码放在 ASP.NET 页面的哪里。在跟踪代码时,错误仅在单步执行页面外部的对象后出现,而不是在设置会话时出现。在设置所有会话对象之后但在页面出错之前,必须有某个地方可以将代码放置在页面上。那会是哪里呢?

I am getting a serialization error trying to use Session State Server instead of InProd. However, I can't figure out what is causing the error in session. I was given some code to add to the page to loop through the session object and figure out if each item in it is serializable. My problem is I don't know where to place the code in the ASP.NET page. In tracing through the code, the error just appears after steping through objects outside of the page and not when setting session. There must be some place that I can place the code on the page that is after all session objects are set but before the page will error. Where would that be?

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

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

发布评论

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

评论(2

葬花如无物 2024-09-22 06:32:56

您可以将其放入页面加载中,设置断点,然后单步执行反序列化代码,直到出现问题为止——这将告诉您哪个对象尚未可序列化,并且正在阻止使用 SQL 进行会话的转换。如果没有提供用于测试可序列化的源代码,则很难判断。

思考一下您在这里要做什么可能会有所帮助。由于 SQL State Server 要求对象可序列化,而 InProc 则不需要,因此放入 Session 中的任何对象都需要可序列化。

因此,您想要验证存储在 Session 中的任何对象是否都是可序列化的,或者,正如其他回答者所说,找出哪个对象不可序列化并导致问题。

测试对象是否可以序列化非常容易< /a>.您可以使用提供的示例代码,或者只是创建一个单元测试(或者在应用程序的页面加载中进行测试,如果这更容易的话)来测试您在会话中存储的各种可序列化类型。

You could put it in pageload, set a breakpoint and then step through the deserializing code until it barfs -- that will tell you which object isn't serializable yet and is blocking the transiton to using SQL for sessions. It's hard to tell without the source code you were given to test for serializable.

It might help to think through what you're trying to do here. Because SQL State Server requires objects to be Serializable where InProc does not, any object you put into Session needs to be Serializable.

So you want to validate that any objects you store in Session are Serializable, or, as the other answerer said, figure out which object isn't Serializable and causing the problems.

It's pretty easy to test whether an object can be Serialized. You can use the sample code you were given or just create a unit test (or test in a pageload for your app if that's easier) that tests the various types you store in session as serializable.

江城子 2024-09-22 06:32:56

这个问题的答案是将代码放置在 SaveStateComplete 事件处理程序中。

The answer to this question is to place the code in the SaveStateComplete event handler.

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