在验证Cookie的ASP.Net存储用户数据 [英] ASP.Net Store User Data in Auth Cookie

查看:141
本文介绍了在验证Cookie的ASP.Net存储用户数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想存储像在auth cookie的用户数据部分中的用户的昵称和用户ID(表中的主键)的一些数据。我这样做的原因是,当浏览器关闭时,无需用户重新登录,以保留这些数据。

I want to store some data like the user nickname and user ID (table primary key) in the user data section of the auth cookie. The reason I'm doing this is to retain this data when the browser is closed, without having the user relogin.

修改:哎呀!意识到自己没有解释自己好。我不是想重新进行身份验证基于他们的cookie的用户。用户的按ASP.Net的会员体系认证 - 这部分是好的。我的问题是,如果我想显示用户的昵称,例如,我不得不解雇了另一个SQL查询,然后将其存储在会话中。我想这将是有意义的存储在cookie的权威性(同样,已经ASP.Net创建的)中的UserData部分,它似乎已经为此创建了这一信息。

Edit: Whoops! Realized I'd not explained myself well. I am not trying to reauthenticate a user based on their cookie. The user is already authenticated by ASP.Net's membership system - this part is fine. My problem is that if I want to show the user's nickname, for example, I have to fire off another SQL query, and then store it in the session. I figured it would make sense to store this information in the auth cookie (again, the one already created by ASP.Net) in the UserData section, which seems to have been created for this purpose.

我不希望因为我有我自己的用户表,文件数据使用的配置文件,我需要一个轻量级的解决方案。

I don't want to use profiles because I have my own user table with profile data, and I needed a lightweight solution.

什么是一个很好的方式连接code此数据在身份验证cookie的用户数据区?我在想系列化,但可能是矫枉过正。我要对这个错误的方式?

What is a good way to encode this data in the user data section of the auth cookie? I was thinking serialization, but that might be overkill. Am I going about this the wrong way?

推荐答案

我在深入教程如何做到这一点在这里写的:

I've written an in depth tutorial on how to do this here:

<一个href=\"http://www.danharman.net/2011/07/07/storing-custom-data-in-forms-authentication-tickets/\">http://www.danharman.net/2011/07/07/storing-custom-data-in-forms-authentication-tickets/

这保持了加密和认证,并使用JSON序列化类进入的UserData字段中。

This maintains the encryption and authentication, and uses json to serialize a class into the UserData field.

这篇关于在验证Cookie的ASP.Net存储用户数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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