从类库访问会话对象 [英] access session object from classlibrary
问题描述
我正在开发一个使用两个子项目的应用程序体系结构:a)asp.net Web应用程序(涵盖用户界面和业务逻辑)和b)类库. (它涵盖了数据访问层)
系统用户成功登录后,用户信息将存储在会话对象中.
我面临的问题是,当我尝试访问类库项目(数据访问层)中的该会话对象时,它始终返回null.
我需要访问类库项目中的会话对象,因为在我的情况下,每个用户都有用于数据库访问的自己的用户名和密码(出于安全原因);
因此,如何在类库项目
可能有帮助
使用 System.Web.SessionState; /// < > /// Class1的摘要描述 /// < /summary > 公共 class Class1:IRequiresSessionState { 公共 Class1() { // // TODO:在此处添加构造函数逻辑 // } 公共 对象 GetSession(字符串键){ 对象 sessionKey = HttpContext.Current.Session [key]; 返回 sessionKey; } }
非常感谢raju melveetilpurayil,我尝试了您的代码,在我所质疑的情况下效果很好.
但是现在,我需要在Web项目和类库项目之间实现wcf层.
现在,我的Web应用程序(用户界面)调用wcf服务(我的服务/功能),并且wcf与类库(数据访问层)进行交互.
Web应用程序< =====> WCF< =====>类库< =====>数据库
我如何实现与上一个方案所解决的相同的事情.
I am developing an application architecture that uses 2 sub projects: a) asp.net web application (it covers user interface and business logic) and b) class library. (it covers data access layer)
After system user successfully logs in , the user information is stored in a session object.
The problem i am facing is when i try to access that session object in class library project(data access layer), it always returns null.
I need to access the session object in class library project because, in my case each user has their own username and password for database access(for security reasons);
So, How how do i read and write from/to session object in class library project
might help
using System.Web.SessionState; /// <summary> /// Summary description for Class1 /// </summary> public class Class1:IRequiresSessionState { public Class1() { // // TODO: Add constructor logic here // } public object GetSession(string key) { object sessionKey = HttpContext.Current.Session[key]; return sessionKey; } }
thank u very much raju melveetilpurayil,i tried your code and it works quite well for the scenario i questioned about.
but now, i need to implement wcf layer between web project and class library project.
Now My web application(User Interface) calls wcf service(My services/functions) and wcf interacts with the class library(data access layer).
Web Application <=====> WCF <=====> Class Library <=====> Database
how do i achieve the same thing that you solved for previous scenario.
这篇关于从类库访问会话对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!