2013-11-04 45 views
1

下面是JAVA中編寫在控制器中的代碼。我將購物車對象保存在HttpSession中,以便我可以在同一個會話中始終檢索它。有沒有辦法在C#中做類似的事情?C#中等價的HttpSession

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 
    System.out.println("in servlet"); 
    Cart cart = getCartFromSession(request); 
} 

Cart getCartFromSession(HttpServletRequest req){ 
    HttpSession session = req.getSession(true); 
    Cart cart=(Cart)session.getAttribute("cart"); 
    if(cart==null){ 
     cart = new Cart(); 
     session.setAttribute("cart", cart); 
    } 
    return cart; 
} 

回答