In a web application which I found it has been decided the user must have logged in or registered as a new user before they can either view the shopping cart or place an item in it. So if the user selects an item to add to the cart and they are not logged in, they must be forced to login or register. My question is, what is the main approach to handling this situation in ASP.NET?
Share
I don’t think it’s a good idea (business wise) to only allow the addition of items to cart if the users are logged in, but I leave that to you.
The approach you need to take depends on your specs which aren’t 100% clear. I assume your catalog and product pages are public accessible and I expect you want the user to login in with his credentials and also add the item to the cart and then go back to the product page as well?
A use-case of what you want could be the following:
If the user clicks on add item to cart, do a postback and check if the user is logged in and – if so – add the item (use-cases ends) otherwise redirect to the login page add remember (session, querystring, cookies) the item you want to add.
User enters credentials and the system checks if there is a pending item to add and – if so – adds the item to the cart.
The system redirects the user back to the product page.