简体   繁体   English

如何在Asp.Net MVC3中使用会话

[英]How to use Session in Asp.Net MVC3

I wants to create session in my project. 我想在我的项目中创建会话。

i want to know the information about session,its syntax, and method to create it. 我想了解有关会话,其语法和创建方法的信息。

first i searched it in google and other websites but no any basic solution found. 首先,我在Google和其他网站上进行了搜索,但未找到任何基本解决方案。

so does anyone tell me how to and where to create session in mvc3 Asp.Net C#. 所以没有人告诉我如何在mvc3 Asp.Net C#中创建会话以及在哪里创建会话。

Thank you in advance. 先感谢您。

If you want to add data to the session you can use 如果要向会话添加数据,可以使用

Session["your key"] = your value or object;

to retrieve data you can use 检索您可以使用的数据

var Val = Session["your key"];

if you want to store and get strongly typed objects you can add them in the same way and just cast them when you receive 如果您要存储并获取强类型对象,则可以以相同的方式添加它们,并在收到时将其强制转换

Session["your key"] = new YourObject();

YourObject obj = (YourObject)Session["your key"] ;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM