TAILIEUCHUNG - Pro ASP.NET MVC Framework phần 4

Trong một số bài viết về cách implement MVC cho , các tác giả thường cho rằng Code Behind của 1 trang là controller, các file aspx, ascx chính là các View. Theo tôi điều này chỉ đúng một phần vì các nguyên nhân | 146 CHAPTER 5 SPORTSSTORE NAVIGATION AND SHOPPING CART separate form tag in each case. And why is it important to use POST here not GET Because the HTTP specification says that GET requests must be idempotent . not cause changes to anything and adding a product to a cart definitely changes the cart. You ll hear more about why this matters and what can happen if you ignore this advice in Chapter 8. Giving Each Visitor a Separate Shopping Cart To make those Add to cart buttons work you ll need to create a new controller class CartController featuring action methods for adding items to the cart and later removing them. But hang on a moment what cart You ve defined the Cart class but so far that s all. There aren t yet any instances of it available to your application and in fact you haven t even decided how that will work. Where are the Cart objects stored in the database or in web server memory Is there one universal Cart shared by everyone does each visitor have a separate Cart instance or is a brand new instance created for every HTTP request Obviously you ll need a Cart to survive for longer than a single HTTP request because visitors will add CartLines to it one by one in a series of requests. And of course each visitor needs a separate cart not shared with other visitors who happen to be shopping at the same time otherwise there will be chaos. The natural way to achieve these characteristics is to store Cart objects in the Session collection. If you have any prior ASPNET experience or even classic ASP experience you ll know that the Session collection holds objects for the duration of a visitor s browsing session . across multiple requests and each visitor has their own separate Session collection. By default its data is stored in the web server s memory but you can configure different storage strategies in process out of process in a SQL database etc. using . MVC Offers a Tidier Way of Working with Session Storage So far this discussion

Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.