下面是在控制器内部编写的JAVA代码.我将购物车对象保存在HttpSession中,以便我可以为同一个会话检索它.有没有办法在C#中做类似的事情?
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;
}
Run Code Online (Sandbox Code Playgroud)