2

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.

4

2 回答 2

1

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.

<profile defaultProvider="ProjectProfile" inherits="MyLib.ProjectProfile, MyLib">
    <providers >
         <clear/>
        <add name="ProjectProfile" type="MyLib.ProjectProfileProvider, MyLib" />
    </providers>
</profile>

And you can even use it for not logged in users! That could be done via usage of another web.config setting:

<anonymousIdentification enabled="true" />

Which will support unique cookie for any user

于 2012-10-19T08:01:34.407 回答
0

A simple shopping cart solution is to just use cookie in the user's browser, since the data stored, is not important to the user or to the website, here's a sample: http://www.codeproject.com/Articles/93639/Simple-Shopping-Cart-Basket-User-Control-using-ASP

You could read more about cookie:

http://msdn.microsoft.com/en-us/library/ms178194(v=vs.100).aspx

However by using cookies you only get access to the data when user is visiting the website with the same browser, if it is matter to you, you can go with database solution, believe me database is much faster than reading/writing xml file, you can also clear up database when user order is complete

于 2012-10-19T07:58:25.873 回答