ASP.NET MVC4 中怎么用sesstion
用ASP.NET MVC4做了个网上书店系统当用户点击“购买”时,需要获得当前用户的ID,我用的是VS2012上自带的注册登录功能,我在网上看到要用sesstion实现,但是没找到具体的使用sesstion的例子,麻烦大家给说说怎么在项目中使用sesstion啊,希望具体点,刚学习这个,还什么都不懂!先谢谢了 --------------------编程问答-------------------- membership get user id --------------------编程问答-------------------- User.Identity.IsAuthenticated就可以了。 --------------------编程问答-------------------- User.Identity.IsAuthenticated返回bool类型的值啊,我想得到当前用户的ID,cart.UserId = User.Identity.IsAuthenticated就会报错。还有我试了试User.Identity.Name, 代码:string name = User.Identity.Name;
int userid = from o in db.UserProfiles where name == o.UserName selecto.UserId;,
这样第二句就又不对了。麻烦您给看看怎么解决? --------------------编程问答-------------------- int userid = (from ... select o.userid).First(); --------------------编程问答-------------------- 试一下这样 int userid = from o in db.UserProfiles where name == Session["UserName"] selecto.UserId;,session的值由你选择购买时的值传过来 --------------------编程问答-------------------- Session使用很简单吧,你就把它当一个容器,直接用Session["UserName"]=XXX
补充:.NET技术 , ASP.NET