重复的cookie查询或存储在viewstate?哪个是更好的做法? [英] Repeated cookie query or Storing in viewstate? Which is the better practice?

查看:213
本文介绍了重复的cookie查询或存储在viewstate?哪个是更好的做法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个内部网站,用户登录。此数据将另存为Cookie。从那里用户去他们的快乐的方式。每隔一段时间,应用程序将查询认证记录以确定用户具有什么权限。

I have a internal website that users log into. This data is saved as a cookie. From there the users go on their merry way. Every so often the application(s) will query the authentication record to determine what permissions the user has.

我的问题是:在需要时查询用户数据的cookie,或者在viewstate中保存用户信息,效率会更高吗?

My question is this: Is it more efficent to just query the cookie for the user data when it is needed or to save the user information in viewstate?

如下所述,Session也是一个选项。

As mentioned below, Session is also an option.

推荐答案

Viewstate特定于他们正在查看的网页,因此它一旦沿着快乐的方式走了。不是一个好的方式来持久化数据。

Viewstate is specific to the page they are viewing, so its gone once they go along thier merry way. Not a good way to persist data.

您最好的选择是使用Forms Authentication,它内置于ASP.NET,您还可以将任何特定于用户的信息推送到Forms身份验证票证的值中。你可以得到4000字节(加密后),应该可以容纳任何你需要的。它还将允许和拒绝用户访问网站上的网页,您可以将其设置为在任何时候到期。

Your best bet is to use Forms Authentication, its built in to ASP.NET and you can also shove any user-specific information into the Forms Authentication Ticket's Value. You can get 4000 bytes in (after encrypting) there that should hold whatever you need. It will also take care of allowing and denying users access to pages on the site, and you can set it to expire whenever you need.

在会话中保存一个 no-no ,因为它的扩展性非常差(占用服务器上的资源),并且对于具有到同一服务器的多个浏览器连接的用户来说可能是恼人的。它有时是不可避免的,但你应该采取巨大的痛苦,以避免它,如果你可以。

Storing in the session is a no-no because it scales VERY poorly (eats up resources on the server), and it can be annoying to users with multiple browser connections to the same server. It is sometimes unavoidable, but you should take great pains to avoid it if you can.

这篇关于重复的cookie查询或存储在viewstate?哪个是更好的做法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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