I’m developing an e-trade web application in ASP.NET.
To buy anything,first, users have to login. Let’s say user logged in and started to shop. When user taps to btnBuy, i’m adding this item to a collection. Everything is working well so far.
Suppose that user bought something,bought means here, i added item chosen to theBasket which contains all the items chosen,then closed the web browser. What i do want to do is to store this data to be able to retrieve this data when user comes back. So,users are able to pick up where they leave off.
So far,i think of 2 options:
1-)Use XML file to retrieve data : I can use XML file to retrieve data but,here the problem is when user deleted an item chosen,i need to parse all the XML file to delete item chose,well ,what i think it’s expensive.It makes the application very slower.
2-) Store in database : I think of storing in the database,but i think it’s expensive as well. Because,every time users pick or leave someting, i need to make connection ,request ,query etc.
Do u guys any idea,what is the best way to do that ? Am i on the right track here ?
Thank you.
ASP.NET provides for such kind of storage built in solution, based on a Manager pattern: called Profile. MSDN link where to start investigate the details: http://msdn.microsoft.com/en-us/library/2y3fs9xs%28v=vs.100%29.aspx
Profile could be accessed via System.Web.HttpContext.Current.Profile almost anywhere (where appropriate of course in n-tier). The basic object is of a type ProfileBase. But you can inject yours. And There is also ProfileProvider (some default available in APS.NET as SqlProfileProvider) or you can inject yours. Later you can change your provider to target XML, DB… as needed (e.g. in a web farm more suitable would be DB) and also use some performance hints like Cache.
This snippet from web.config shows how to put Profile in play.
And you can even use it for not logged in users! That could be done via usage of another web.config setting:
Which will support unique cookie for any user