ASP.NET Identity 2 是否支持匿名用户? [英] Does ASP.NET Identity 2 support anonymous users?

查看:24
本文介绍了ASP.NET Identity 2 是否支持匿名用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想允许匿名/尚未注册和注册的用户在我的网站上发帖.

I want to allow anonymous/not yet registered and registered users to post on my website.

Posts (table)
- Id (int)
- Subject (nvarchar)
- Body (nvarchar)
- UserId (uniqueidentifier)

该项目使用最新的 MS 技术(ASP.NET MVC 5+、C#...)我应该如何去做?

The project uses the latest MS technologies (ASP.NET MVC 5+, C#...) How should I go about doing that?

ASP.NET Identity 是否是正确的解决方案?

Is ASP.NET Identity even the right solution?

它们之间有什么区别:

  • ASP.NET 标识
  • 简单的会员资格
  • 会员提供商

更新我需要能够区分尚未注册的用户并在数据库中记录他们的帖子.

Update I need to be able to differentiate not yet registered users and record their postings in the database.

更新 2然后可以选择迁移到注册帐户.就像 stackoverflow 过去允许匿名用户一样.类似这样但与 ASP.NET Identitfy 兼容的东西http://msdn.microsoft.com/en-us/library/ewfkf772(v=vs.100).aspx

Update 2 Then have the option to migrate to a registered account. Just like how stackoverflow used to allow anonymous users. Something like this but compatible with ASP.NET Identitfy http://msdn.microsoft.com/en-us/library/ewfkf772(v=vs.100).aspx

推荐答案

我想回答一个原始问题:我需要能够区分尚未注册的用户并将他们的帖子记录在数据库中.".

I want to answer one of the original questions: "I need to be able to differentiate not yet registered users and record their postings in the database.".

我之前使用过 Simple Membership 并且我正在使用 Asp.Net Identity Framework2.2.1.在这两种情况下,我都使用匿名身份来区分尚未注册的用户和经过身份验证的用户.

I have used Simple Membership before and I am using Asp.Net Identity Framework 2.2.1. In both cases I use anonymous identification to differentiate not yet registered users and authenticated users.

  1. 通过添加 <anonymousIdentification enabled="true" cookieName="YOUR_COOKIE_FOR_ANONYMOUS_IDENTIFICATION"/> 在您的 Web.config 中启用匿名识别.
  2. 您可以通过 Request.AnonymousID 获取匿名 ID.该 ID 是字符串格式的 GUID.
  3. 正如其他用户提到的,您可以使用任何您想要的身份系统,只需记住在注销过程中清除匿名 ID.通常在用户成功通过身份验证后,您将用户名/用户 ID 与匿名 ID 保存到持久性存储中.通过在用户注销时清除 anonymousId,您可以确保其他经过身份验证的用户将无法与相同的 anonymousId 关联.
  4. 您可以通过AnonymousIdentificationModule.ClearAnonymousIdentifier()清除anonymousId.注意:AnonymousIdentificationModule 在 System.Web.Security 程序集中.您可以添加 System.Web 的引用或使用 CTRL + "."在代码中的 AnonymousIdentificationModule 上引入 System.Web.Security.
  1. Enable anonymous identification in your Web.config by adding <anonymousIdentification enabled="true" cookieName="YOUR_COOKIE_FOR_ANONYMOUS_IDENTIFICATION" />.
  2. You can get the anonymous id by Request.AnonymousID. That id is a GUID in string format.
  3. As other users mention, you can use whatever identity system you want, just remember to clear the anonymous id during the log out process. Typically after a user is successfully authenticated, you save either the username / userId with the anonymousId into persistence storage. By clearing the anonymousId when the user logs out, you can make sure the other authenticated users won't be able to associate with the same anonymousId.
  4. You can clear the anonymousId by AnonymousIdentificationModule.ClearAnonymousIdentifier(). Note: the AnonymousIdentificationModule is in System.Web.Security assembly. You can add a reference of System.Web or use CTRL + "." on the AnonymousIdentificationModule in your code to bring in System.Web.Security.

这篇关于ASP.NET Identity 2 是否支持匿名用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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