Click here to Skip to main content
12,401,984 members (51,521 online)
Rate this:
 
Please Sign up or sign in to vote.
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:00pm
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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  
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.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

To store the textbox value into session.

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


Thanks
  Permalink  
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 ?
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

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
Top Experts
Last 24hrsThis month


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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100