本文介绍了存储使用FormsAuthentication.SetAuthCookie更多信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的aspx和c#的设置身份验证cookie进行登录。

I am using aspx and c# for a setting a authentication cookie for a login.

FormsAuthentication.SetAuthCookie(UserName, True)

我要存储在同一个cookie的更多信息。我可以值添加到此身份验证cookie或者我必须使用第二个的HTTP cookie?

I want to store more information in the same cookie. Can I add values to this authentication cookie or do I have to use a second http cookie?

基本上,我在寻找客场存储用户的编号所以我可能能够使用用户表行键访问数据库

Basically I'm looking for away to store the User's Id so I may be able to access the database using the users table row key

谢谢,
伊甸园

Thanks,Eden

推荐答案

您可以将用户数据添加到的FormsAuthenticationTicket,然后生成cookie的自己。

You can add user data to the FormsAuthenticationTicket, then generate the cookie yourself.

有一个在the MSDN文档的FormsAuthenticationTicket 。

修改

请注意在创建时票,你需要设置超时时间,这在一般你会想是一样的web.config中配置的值。不幸的是,框架3.5或更早版本, FormsAuthentication 类不会公开暴露超时。对于一个变通方法,使用在响应中描述的技术之一this连接反馈项。

Note that when creating the ticket, you need to set the timeout, which in general you will want to be the same as the value configured in web.config. Unfortunately, in the Framework 3.5 or earlier, the FormsAuthentication class does not expose this timeout publicly. For a workaround, use one of the techniques described in the response to this connect feedback item.

更新

连接反馈项目不再出现,可悲。希望你简要介绍一下技术是。

是的,这是一个遗憾微软已经抛弃的历史连接的项目。 IIRC,这两种技术他们建议是:

Yes, it's a pity Microsoft has discarded historical Connect items. IIRC, the two techniques they suggested were:


  1. 使用WebConfigurationManager读取相关的配置部分,并获得超时值。

  1. Use WebConfigurationManager to read the relevant configuration section and get the timeout value.

使用 FormsAuthentication.GetAuthCookie ,使用解密创建一个cookie FormsAuthentication.Decrypt 和检查生成的FormsAuthenticationTicket

Create a cookie using FormsAuthentication.GetAuthCookie, decrypt it using FormsAuthentication.Decrypt and inspect the generated FormsAuthenticationTicket.

或升级到.NET 4.x的地方有一个 FormsAuthentication.Timeout 属性。

Or upgrade to .NET 4.x where there is a FormsAuthentication.Timeout property.

请参阅

这篇关于存储使用FormsAuthentication.SetAuthCookie更多信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 11:52
查看更多