是否可以访问登录用户的 ASP.NET 匿名配置文件?

发布于 2024-08-10 06:19:01 字数 522 浏览 4 评论 0原文

ASP.NET 成员资格支持匿名用户和登录用户。

如果您调用 FormsAuthentication.SetAuthCookie(userName, createPersistentCookie); 并为 createPersistentCookie 设置为 true,那么用户在重新访问您的网站时将自动登录。网站 - 即使关闭浏览器后也是如此。如果您不启用此“记住我”功能,那么当用户再次访问您的网站时,匿名 cookie 仍将存在。

我希望能够在用户登录时将信息存储在用户的匿名个人资料中。即,如果他们离开并回来,我不希望他们在网站上保持身份验证,但我仍然希望能够跟踪某些事情 - 例如匿名配置文件中的 visitCount 属性。

有没有办法在用户经过身份验证后访问其匿名个人资料。这两个 cookie 存在,所以应该是可能的。我不想重新发明半个轮子!

附:我意识到,如果多个用户使用该系统,跟踪就会出现偏差,但这没关系。

The ASP.NET membership supports anonymous users and logged in users.

If you call FormsAuthentication.SetAuthCookie(userName, createPersistentCookie); with a true for createPersistentCookie then the user will be logged in automatically when they revisit your site - even after closing the browser. If you don't enable this 'remember me' feature, then the anonymous cookie will still be around when the user visits your site again.

I'd like to do be able to store information in the user's anonymous profile when they are logged in. i.e. I don't want them to remain authenticated on the site if they go away and come back, but I'd still like be able to track certain things - like perhaps a visitCount property in the anonymous profile.

Is there any way to access a user's anonymous profile when they are authenticated. The two cookies exist so it should be possible. I don't want to reinvent half the wheel!

ps. I realize that tracking is skewed if multiple users use the system but thats fine.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

温柔少女心 2024-08-17 06:19:01

当然。只需检查 RequestAnonymousId 属性并构建 ProfileBase 即可。

var anonymousID = Request.AnonymousID;
if (anonymousID != null)
{
    var profile = ProfileBase.Create(anonymousID, false);

    int counter = (int)profile["counter"];
    profile["counter"] = ++counter;
    profile.Save();
}

Sure. Simply check the AnonymousId property of the Request and built a ProfileBase.

var anonymousID = Request.AnonymousID;
if (anonymousID != null)
{
    var profile = ProfileBase.Create(anonymousID, false);

    int counter = (int)profile["counter"];
    profile["counter"] = ++counter;
    profile.Save();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文