there's an up and running self-serve customer portal built that I'm trying to make a bit better when it comes to displaying proper items for different client types and auto-logging users. Here are a few considerations:
- Built on ASP.NET MVC (4.7.2)
- Authentication Mode = Forms
- Uses custom Membership Provider
- Uses various cookies and the session to store relevant data
- Hosted in the cloud. Load balancers and everything. Traffic is increasing, and fast.
And here are some requirements
- The portal has a 'remember me' functionality. If the session has expired and a customer types www.sampleSite.com/sampleController/sampleAction, it should automatically log them in.
- The portal has a log out functionality, of course.
- There are different customer types that need to see different menu items and UI items. I need this information both on clientside and on serverside.
For better maintenance (it's not fairly decoupled as it is) and some issues with the load balancing, I'm doing some code maintenance and here's what I want to get rid of:
if (this.Session["CurrentUserIsTypeA"] == true) {...} else if (this.Session["CurrentUserIsTypeB"] == true) {...}
- Queries to the database e.g.
var customer = loginsService.GetByEmail(this.User.Identity.Name)
and then passing data to e.g. ViewBag
So basically I need to either somehow extend the IIdentity so it includes the data I need, use a custom Profile Provider and call it as this.Profile.PropertyValues
or even migrate to ASP.NET Identity following Microsoft's docs. (I am fairly familiar with the roles and claims from .NET Core projects, unlike profiles and membership).
- Which of these would you choose? I'd say using a custom profile provider is faster and easier, but is ASP.NET Membership still a good choice for ASP.NET MVC applications in 2019?
- How to implement the 'remember me' functionality with minimal risk for customers? What I'm doing right now is I'm generating a random token that I save to the database and then send as a cookie. When the session expires and the client is auto-logged via that token, it gets replaced with a new one. Security-wise, I'm worried about stealing the cookie and logging on a different computer. What would be some best-practices for protecting a cookie?
- What's the best practice for "Remember Me" and "Log Out"? If someone manually clicks log out, it would be fair to say they want the cookie gone, right?