I am developing an e-commerce app using asp.net mvc.
我正在使用asp.net mvc开发一个电子商务应用程序。
After user successfully logged into system the application is pulling additional data from database (favorites, order history, unfinished cart etc.)
用户成功登录系统后,应用程序将从数据库中提取其他数据(收藏夹,订单历史记录,未完成的购物车等)
What is the best way to pull that data in case if user used Remember me option?
如果用户使用“记住我”选项,那么提取数据的最佳方法是什么?
I am thinking to check if user is authenticated and additional data is not already loaded on master page but is seems not the best solution.
我正在考虑检查用户是否已经过身份验证,并且主页上尚未加载其他数据,但这似乎不是最佳解决方案。
1 个解决方案
#1
1
I have a user class that collects all of those bits together.
我有一个用户类一起收集所有这些位。
On session start, I check for authentication, create it, populate it, and store it in the session variable. Then you can access it from wherever you please (I've also created a Globals static class that gets/casts objects from the session and application variables.) Alternatively, you could do it on each page load.
在会话开始时,我检查身份验证,创建它,填充它,并将其存储在会话变量中。然后你可以从任何你喜欢的地方访问它(我还创建了一个Globals静态类,它从会话和应用程序变量中获取/转换对象。)或者,你可以在每个页面加载时执行它。
The above takes care of returning users. But you also have to remember to create it on login, and destroy it on logout (from the Accounts controller).
以上内容负责返回用户。但是你还必须记住在登录时创建它,并在注销时(从Accounts控制器)销毁它。
Also, I would suggest you think about what exactly needs to be stored in this way. The session variable is great to cache this data, but I don't know if order history needs to be cached. That's generally only accessed occasionally. In fact, even if you choose not to put the class in the session, and to create it on each page load, it seems like overkill to get order history. (Either way you're wasting resources -- storing it in the cache or collecting it frequently.)
另外,我建议你考虑一下这种方式需要存储的确切内容。会话变量非常适合缓存此数据,但我不知道是否需要缓存订单历史记录。这通常只是偶尔访问。实际上,即使您选择不将类放在会话中,并在每个页面加载时创建它,获取订单历史记录似乎有点过分。 (无论哪种方式,你都在浪费资源 - 将其存储在缓存中或经常收集它。)
James
#1
1
I have a user class that collects all of those bits together.
我有一个用户类一起收集所有这些位。
On session start, I check for authentication, create it, populate it, and store it in the session variable. Then you can access it from wherever you please (I've also created a Globals static class that gets/casts objects from the session and application variables.) Alternatively, you could do it on each page load.
在会话开始时,我检查身份验证,创建它,填充它,并将其存储在会话变量中。然后你可以从任何你喜欢的地方访问它(我还创建了一个Globals静态类,它从会话和应用程序变量中获取/转换对象。)或者,你可以在每个页面加载时执行它。
The above takes care of returning users. But you also have to remember to create it on login, and destroy it on logout (from the Accounts controller).
以上内容负责返回用户。但是你还必须记住在登录时创建它,并在注销时(从Accounts控制器)销毁它。
Also, I would suggest you think about what exactly needs to be stored in this way. The session variable is great to cache this data, but I don't know if order history needs to be cached. That's generally only accessed occasionally. In fact, even if you choose not to put the class in the session, and to create it on each page load, it seems like overkill to get order history. (Either way you're wasting resources -- storing it in the cache or collecting it frequently.)
另外,我建议你考虑一下这种方式需要存储的确切内容。会话变量非常适合缓存此数据,但我不知道是否需要缓存订单历史记录。这通常只是偶尔访问。实际上,即使您选择不将类放在会话中,并在每个页面加载时创建它,获取订单历史记录似乎有点过分。 (无论哪种方式,你都在浪费资源 - 将其存储在缓存中或经常收集它。)
James