与状态服务器asp.net获取会话数据的成本 [英] Getting session data cost in asp.net with state server

查看:98
本文介绍了与状态服务器asp.net获取会话数据的成本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用ASP.NET会话状态服务器为我的网站之一。我把一个用户对象的会话,因为它使用了很多。

I'm using the ASP.NET session state server for one of my websites. I put a user object in session because it is used a lot.

考虑以下code片段:

Consider the following code fragment:

DoSomething(SessionUser.Me.UserID)
DoSomeMore(SessionUser.Me.UserName)

SessionUser.Me是少了点东西就像一个静态属性:

SessionUser.Me is a static property that just does something like:

return (SessionUser)Session["currentuser"];

现在,因为我访问SessionUser.Me 2倍(DoSomething的和DoSomeMore)是.NET足够聪明,不会做2往返到的StateServer和反序列化的2倍?

Now because I access SessionUser.Me 2 times (DoSomething and DoSomeMore) is .NET smart enough to not do 2 roundtrips to the stateserver and deserialize 2 times?

与其他词是等值的性能,如果我只是做了:

With other words is it equivalent in performance if I just did:

var user = SessionUser.Me;
DoSomething(user.UserID)
DoSomeMore(user.UserName)

推荐答案

会议是在请求管道初期状态服务器(见的 HttpApplication.AcquireRequestState ,并写回页面执行完成时状态服务器(见的 HttpApplication.ReleaseRequestState )。

Session is deserialized from the state server early in the request pipeline (see HttpApplication.AcquireRequestState, and written back to the state server when execution of the page completes (see HttpApplication.ReleaseRequestState).

因此​​,你不应该重复访问招致性能损失。

Thus, you shouldn't incur a performance hit from repeated access.

这篇关于与状态服务器asp.net获取会话数据的成本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆