How to use sessions in an ASP.NET MVC 4 application?

后端 未结 5 1464
离开以前
离开以前 2020-11-22 17:02

I am new to ASP.NET MVC. I have used PHP before and it was easy to create a session and select user records based on the current session variables.

I have looked ev

5条回答
  •  温柔的废话
    2020-11-22 17:46

    Try

    //adding data to session
    //assuming the method below will return list of Products
    
    var products=Db.GetProducts();
    
    //Store the products to a session
    
    Session["products"]=products;
    
    //To get what you have stored to a session
    
    var products=Session["products"] as List;
    
    //to clear the session value
    
    Session["products"]=null;
    

提交回复
热议问题