本文介绍了BAL(3层)层中的会话访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,
我已经在3层创建了Web应用程序,并且我想在会话中存储登录用户信息并希望在BAL中访问。
Hello,
I Have Created Web Application in 3-Tier, and I Want to Store Login User Info in Session and want To Access in BAL.
推荐答案
HttpContext.Current.Session["MySession"]
其次正确方式是
i)创建一个引用System.Web的类库。在这个项目中创建Class Say ClsStateManagement。
在类中添加一个属性
Secondly Proper way is
i)Create a class library which has a reference to System.Web. create Class Say ClsStateManagement in this project.
Add a property to the class
public string UserId
{
get
{
return (string)HttpContext.Current.Session["UserId"];
}
set
{
HttpContext.Current.Session["UserId"]=value;
}
}
ii)将此项目的引用添加到UI和BAL
现在在你的ASPX.CS(用户界面)
ii) Add reference of this project to both you UI and BAL
Now in you ASPX.CS (in UI)
ClsStateManagement c=new ClsStateManagement()
c.UserId="MyUserId";
BAL
in BAL
ClsStateManagement c=new ClsStateManagement()
string myUserId=c.UserId;
如果有帮助,请将此标记为corerct答案。
Mark this as corerct answer if it helped.
Session["userid"]=txtUserName.Text.Trim()
谢谢
Thanks
这篇关于BAL(3层)层中的会话访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!