Last post Jun 30, 2017 08:26 AM by AngelinaJolie
Jun 29, 2017 02:04 PM|Ponant|LINK
I am implementing a website with .Net Core 2.0 (preview as of now) using the MVC framework and the html is generated with razor views. My db's are SQL and all will run in Azure. I want to allow a user to shop for products, but this user can be anonymous
while shopping, i.e. unlogged and unregistered. Unfortunately, I have no clue on how to store the product(s) that the shopper will select (Add to Cart button), and then how to process them once he decides to "proceed to checkout". Upon proceeding to checkout,
I need to be able to list what he selected and display it to him.
I heard about session state and local storage but there are perhaps other ways. I wonder if it is not even possible to store the data in SQL on the server, but I do not know how to identify the anonymous user in that case. I welcome any advice on the matter
and I am looking for the most secure procedure, even if the UX is to be a bit altered, and be able to handle many users.
Jun 29, 2017 03:19 PM|bruce (sqlwork.com)|LINK
I'd create a database to store the shopping cart in, so you can keep it for weeks/months (have an expiration data, so you can purge). You can store the shopping cart id in a cookie. if the user logins in, attach the cart to the user (user/cart relation).
note: remember if you keep the cart for days, to revalidate inventory and price when you load it.
Jun 29, 2017 04:36 PM|Ponant|LINK
Thank you for your response. Do you mind -even briefly- explain why this is better than session or local storage (or else of I might not be aware of)? That will help in getting a bigger picture.
Jun 30, 2017 08:26 AM|AngelinaJolie|LINK
want to allow a user to shop for products, but this user can be anonymous while shopping,
I guess that I know what you want is Request.AnonymousID which could be used in MVC directly
Request.AnonymousID is to get the anonymous identifier for the user, if it is available.(for example , guest person views your site via browser on the computer ,then you can get a specifying AnonymousID for this browser of this computer , so you could
store AnonymousID to database as key for storing more information using sql server )
Then here are two ways to achieve this effort in .net core:
1 : store it with cookies;
var c = Guid.NewGuid().ToString();
2:install NuGet as AnonymousId (ReturnTrue.AspNetCore.Identity.Anonymous)
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
public class HomeController : Controller
public ViewResult Index()
string anonymousId = Request.Headers["AnonymousId"];