Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: C#ASP.NET
Hello Friends,
i have set session while login page. i want to access that value in BAL layer. While i switch to any other page all session value pass null..
Can any one tell me how to solve that.

Thank You All
Posted 31-Jan-13 18:07pm
JemiM at 1-Feb-13 0:10am
set the session value in a static property.
Sergey Alexandrovich Kryukov at 1-Feb-13 0:11am
There are two many ways to screw up things. Show some code sample, if you need help. Please use "Improve question", above. —SA
Yatin chauhan at 1-Feb-13 0:19am
Heloo SA i have did like that but still it get null in all pages.
Sergey Alexandrovich Kryukov at 1-Feb-13 0:25am
I did not advise anything yet. I just say you need to "Improve question", otherwise there is nothing to talk about. Code sample! —SA
JemiM at 1-Feb-13 0:12am
forexample:set session value in a property from where you got the session value like classlibrary.YourclassName.LoginSession=session["userid"]; class YourClassName{public static string LoginSession{get;set;} }
Yatin chauhan at 1-Feb-13 0:14am
I have set that but when i switch to any page all time session get null value. i have set in my BAL layer like this. public string UserName { get { if (HttpContext.Current.Session["UserName"] == null) return null; return HttpContext.Current.Session["UserName"].ToString(); } } public string BranchName { get { if (HttpContext.Current.Session["BranchName"] == null) return null; return HttpContext.Current.Session["BranchName"].ToString(); } }
Sergey Alexandrovich Kryukov at 1-Feb-13 0:26am
OK, and where is the setter? Now, will you move it to the body of the question. "Improve question"... —SA
JemiM at 1-Feb-13 0:18am
don't need to set like this.initialize the vairaible public static UserName{get;set;} public static string BranchName{get;set;}. Set these values from where you got the session values.for example after login and then try to read the property from any of the method from BL.
Yatin chauhan at 1-Feb-13 1:09am
Heloo SA and JemiM Now i set like this in BAL Layer public string UserName { get { return _UserName; } set { _UserName = value; } } public string BranchName { get { return _BranchName; } set { _BranchName = value; } } and in my login page session[CommonInfo]= ObjBAL.CommonInfo now when i first time redirect to Default page all value set as i need like username and brnachname etc.. but when i tried to other page session get null value in that page..
Kishor Deshpande at 1-Feb-13 12:35pm
Check if you have your SessionState Cookieless=false, if it is true, you won't be able to use it across the layers..
Yatin chauhan at 4-Feb-13 3:54am
Hello Kishor Sir, Thank For Information i solve that by your code. Thank You Sir.

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 838
1 OriginalGriff 461
2 Tadit Dash 355
3 sanket saxena 329
4 Peter Leow 228
0 Sergey Alexandrovich Kryukov 11,990
1 OriginalGriff 7,349
2 Peter Leow 5,003
3 Abhinav S 4,003
4 Maciej Los 3,575

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