小编use*_*119的帖子

C#中的HttpSession等价物

下面是在控制器内部编写的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)

c# java asp.net session-state httpsession

1
推荐指数
1
解决办法
2496
查看次数

标签 统计

asp.net ×1

c# ×1

httpsession ×1

java ×1

session-state ×1