Click here to Skip to main content
Sign Up to vote bad
good
See more: C#ASP.NET
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 31 Jan '13 - 18:00


3 solutions

You can do couple of things
 
Simplest way is
Add a reference of system.web to BAL,
then use the following syntax
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
 
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)
ClsStateManagement c=new ClsStateManagement()
c.UserId="MyUserId";
 

in BAL
ClsStateManagement c=new ClsStateManagement()
string myUserId=c.UserId;
 
Mark this as corerct answer if it helped.
  Permalink  
Comments
Member 8372011 - 1 Feb '13 - 1:38
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.
 
Session["userid"]=txtUserName.Text.Trim()
 

Thanks
  Permalink  
Comments
Member 8372011 - 1 Feb '13 - 0:15
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
  Permalink  

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 8,028
1 OriginalGriff 6,010
2 CPallini 3,432
3 Rohan Leuva 2,703
4 Maciej Los 2,234


Advertise | Privacy | Mobile
Web01 | 2.6.130516.1 | Last Updated 1 Feb 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid