ASP.NET Identity is a flexible framework for handling user authentication in your Web App. It's pretty awesome, and I would highly recommend you continue using it in your project.
Identity doesn't support anonymous users, per se...rather, it's a framework for letting you manage users that are authenticated. Identity will let you maintain local users, or if you want, users that authenticate with your web app via an external service (say, Facebook or Google).
It sounds like you want part of your web app to be accessible to users who are not authenticated. The way you'd achieve that is through attributes on your ASP.NET Controllers.
Adding the [Authorize]
attribute to a Controller or Controller method will tell MVC to ensure the user is both authenticated and authorized. However, to allow anonymous users, simply put the [AllowAnonymous]
attribute on the method you want to give public access to.
However, you'll still be able to tell if the user is authenticated or not. Consider this sample controller and method:
[Authorize]
public class PostController : Controller
{
[AllowAnonymous]
public ActionResult Index()
{
var isAuthenticated = User.Identity.IsAuthenticated;
return View();
}
}
That isAuthenticated
will let you know if the current user is logged in or not, and if they are, you can get more information from the User.Identity
object.
In regards to your general question about the differences between the membership frameworks, I'll defer to the official documentation which gives a great overview of the differences: http://www.asp.net/identity/overview/getting-started/introduction-to-aspnet-identity. You definitely want to use ASP.NET Identity in your web app.
Update
Check out this sample code, which will help you differentiate between not yet registered users when recording posts to the database.
[Authorize]
public class PostController : Controller
{
[AllowAnonymous]
public HttpStatusCodeResult CreatePost(string postText)
{
// Use ASP.NET Identity to see if the user is logged in.
// If they are, we can get their User Id (blank otherwise)
var isAuthenticated = User.Identity.IsAuthenticated;
var userId = "";
if (isAuthenticated)
userId = User.Identity.GetUserId();
// Create a new post object
var post = new
{
PostText = postText,
Anonymous = !isAuthenticated,
UserId = userId
};
// Save the post to the database here
return new HttpStatusCodeResult(HttpStatusCode.OK);
}
}