Click here to Skip to main content
15,890,043 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted

You can do couple of things

Simplest way is
Add a reference of system.web to BAL,
then use the following syntax
C#
HttpContext.Current.Session["MySession"]


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

C#
public string UserId
   {
       get
       {
           return (string)HttpContext.Current.Session["UserId"];
       }
       set
       {
           HttpContext.Current.Session["UserId"]=value;
       }
   }


ii) Add reference of this project to both you UI and BAL

Now in you ASPX.CS (in UI)
C#
ClsStateManagement c=new ClsStateManagement()
c.UserId="MyUserId";



in BAL
C#
ClsStateManagement c=new ClsStateManagement()
string myUserId=c.UserId;


Mark this as corerct answer if it helped.
 
Share this answer
 
v4
Comments
Member 8372011 1-Feb-13 1:38am    
Hi,

I Got The alternate but still one more problem,
i set whole Business Layer object in Session after storing info in it,
but it is accessible only before master page load,
after loading master page it returns null...

have you any idea why this happen ????

thanks.
To store the textbox value into session.

C#
Session["userid"]=txtUserName.Text.Trim()



Thanks
 
Share this answer
 
Comments
Member 8372011 1-Feb-13 0:15am    
Thanks,
ya i did this one but after that ?
How can i Access this Value in Business Layer ?
in BAL i use HttpContext.Current.Session["UserId"] but it's always null...
could you pelase help me ?
Hi All,


I Got the Final Solution, The only reason why HttpContext.Current.Session returning null is because i am set CookieLess =true in web.config , which is default false if i want to access HttpContext.Current.Session from outside the web project.

Thanks
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900