.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Defining session variables...

Posted By:      Posted Date: August 27, 2010    Points: 0   Category :ASP.Net


This is a pretty basic question.

I have some code where I need to define a session variable  however it's coming back as Nothing when the code is executed. Here's the code:

' Default Currency

REQCURR = Request.Querystring("p_DCURR")
'If not explicitly specified, try to get it from session

If (REQCURR = "") Then

     If (Session("REQCURR") <> "") Then
          REQCURR = Session("REQCURR")

          'Here is the session variable I'm trying to define:
          Session("REQCAD") = 0
          REQCURR = ""
     End If

End If


So, for some reason that Session("REQCAD") = 0 has no value instead of having a value of 0.

Any thoughts?


View Complete Post

More Related Resource Links

Session and Application Variables


I have a web application in which i need to logout the user if he clicks the logout button or even if he closes his browser window. On Logout button click, i am doing session.Abandon(), but how to go about his browser window close.

Can anybody help with a code sample.

ASP.NET MVC 2 - I have a serious concern about the management of session variables.


I have a serious concern about the management of session variables.
I state that I have Windows Web Server 2008.
Currently values in the controller and call a session variable like this:
I have an action in as:
System.Web.HttpContext.Current.Session ['name'] = id_userlogged;

Need to access session variables in an ashx?

Dear All,In my project i need to set session in an ashx file and access that session in aspx.cs file. for this i am dooing the following things.In .ashx filepublic class Upload : IHttpHandler , System.Web.SessionState.IRequiresSessionState{    public void ProcessRequest(HttpContext context)    {            HttpPostedFile postedFile = context.Request.Files["Filedata"];            context.Session["img"] = postedFile.FileName;    }}After the file upload happand i wrote the code in .aspx.cs fileprotected void Button1_Click(object sender, EventArgs e)    {        Response.Write(Session["img"].ToString());    }this is working fine in IE but in Mozilla,Chrome,safari and Opera i got Session["img"] is null. Any help can be appreciatedThanks & Regards Basheer K M Cybrosys Technologies Pvt. Ltd. Calicut. http://www.cybrosys.com

Using Global.asax to Set Session Variables Pulled From SQLServer

I have a custom class that pulls user information from a SQL Server table. Now that I'm expanding the site from a single page to others. I want to shift the code to the Session_Start event so that the information is always loaded when the site is accessed. How do I call my custom code from global.asax since its script and not a class. 

session variables and master pages

Hi all: I have a master page and 2 content pages. In the master page I use a session variable. As it, I suppose this session variable is read by the two content pages. But it isn't working. This session variable is read by the first content page and not the second. Why? Thanks in advance if you can help me      

Session Variables and Session Timeouts

I added the following code to global.asax to load up several session variable when a session starts. I'm assuming that when a page goes to use the variable that I should be 1) checking at the page level that the value is valid not 0 when its not expected to be 0, not a zero-length string when its expected to have a length 2) have code at the page level that sets the values if the values have not been set as when the Session timeout, ideally putting the code in a class derived from Page and then deriving all of my pages from the new class so that the code does not have to be repeated in every page Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs) ' Code that runs when a new session is started 'Move code here that sets the User Session Variables, currently done in the code behind of DefaultDirectory and the Dashboard Masters Dim ExceptionMessage As New StringBuilder ExceptionMessage.Append("Site accessed using " + Request.Browser.Browser + " " + Request.Browser.MajorVersion.toString + "." + Request.Browser.MinorVersion.tostring) Dim NewException As New NotSupportedException(ExceptionMessage.ToString) Elmah.ErrorSignal.FromCurrentContext().Raise(NewException) Dim CurrentUser As New MercurySiteUser.SiteUser() Session("UserE

Sharing the session variables between two .net applications using SQL Server Mode?

Hi, I have two different IIS applications within the same domain(let us say www.mydomain.com) , both of these applications use the same database instance(same connectionstring), now what I want is that both of applications can see each sessions variables , can SQL Server session state mode helps in this case? Did someone try that before? Is there any other way to share the session variables? Please help.  

How to pass session variables from .net to coldfusion


We are in the process of refactoring from cf to .net, so, I am working on the Login page and converting it from cf to .net. So, when I am autheticated and enter into our website, I need to redirect it to a cfm page (just temporary, since we will be refactoring that also eventually).

So, I am autheticated (using CustomMembership Provider model for sql server) and then when I redirect to the cfm, the app.cfm should validate the .net session variables. Here is where i am stuck:

I have the .net session variables in the aspx side:something like

Session["UserId"].ToString() = Value from a login txt box (also authenticated against data in the database)

Session["UserName"].ToString() = Value from the db corresponding to the User Name entered in the text box.



So, now I have all the session variables in the .net side. Now, how do I retreive these .net session in the cf side? Any small peice of code to retrive the asp.net session variable in the application.cfm side would be great.

ASP.NET session variables, do you need to save each time?


Anytime you change the object variable that is already assigned to a session variable, do you need to "re-save" the variable back into the session variable or does it do it automatically?

For example:

// abc is an object of some random type

Session["abc"] = abc;  // initial declaration of session variable.

abc.a=1;  // updated abc.a field after a button_click event

Session["abc"] = abc;   // resave the new field value of 'a' back into the session variable 'abc'.

Or does the session variable already keep track of all changes made to the object and saves automatically?


Session and session variables not stable in development server....


Hi I have a strange problem in a website that runs in a server to which I am connected through VPN...

I use some session variables to get the job done(shopping cart, etc) but it is not stable..manytimes I get no items in session object and other times(refreshing the page) I get missing data...I downloaded the entire site code to my local pc and debugged it and run it succesfully without any session data missing...When I run it in the server, I get bad session again: no products in shopping cart or products with missing quantities...

The same website runs smoothly in our production server too....The problem is with our development server...

Any help would be greatly appreciated..

Thanks in advance,


Session variables are accessible to multiple users?


I have an asp.net website in which users can submit reports. Another tester and I tested this page at the same time and when I went to review the information I submitted, it displayed information that I didn't submit. It displayed the info submitted from the other user.

I use session variables for these values. I don't understand how this happened?

What can I do so each user can individually submit their information without overlapping some one else's information? The plan is for multiple users to be able to use this page to submit their weekly layer reports.

The first example of code is how I add the session variables from the textboxes.

If Session("BarnNo") = Nothing Then
                                'add session variables
                                    Session.Add("FName", FNameTextbox.Text)
                                    Session.Add("LName", LNameTextbox.Text)
                                    Session.Add("WkEnd", Calendar1.SelectedDate.ToShortDateString())
                                    Session.Add("DisplayDate", Calendar1.SelectedDate.ToLongDateString)

                                    Session.Add("BarnNo", BarnNumberTextbox.Text)
                                    Session.Add("FlockNo", FlockNoTextbox.Tex

Setting Session variables at the time of login authentication


Dear Rahul,

I am having a website in which I am setting nearly 20 Session variables at the time of login authentication. ( Ex : Name, EmpID, Dept, Location, Email...).

Can u please tell which is one of the following is the better way to get Login user details 

 1) Through session variables at the time of login 

 2) In each and every page by calling the Stored Procedure to get login user details


Regards >> HemaBhushan 


Crossing values of Session variables


Hi all,

We are working in a web application using Session variables to store the clients ID to operate with them in all app (making orders, reports, etc....) but randomly users get the client ID of another user in any moment using the application.

I have tried to solve it in a first step adding to system.web section in the web.config file this:

<httpRuntime enableKernelOutputCache="false"/>

No changes after this. I have tried another possible solution, changing the SessionState to StateServer:

<sessionState timeout="30" mode="StateServer" stateConnectionString="tcpip="></sessionState>

ASP.NET State Service is running in server normally, It began run just before this last change, but we have not solved the problem either with this solution.

The server is Windows Server 2003 Standard Edition SP2 32bits running IIS 6.0, and the application is made with Framework 2.0

Are we doing wrong or forget something?


Do Session Variables Persist between HTTP and HTTPS?


Hey guys,

Just wondering whether or not Session Variables that are declared and set while in a HTTP session will continue to exist if the users session moves to HTTPS?


Hope I'm making sense.



Objects in session variables now causing slow-downs..


I've noticed that once I've instantiated 3-4 objects now, my ASPX page is running slower.  The response from the server (which is my own PC) is taking longer.

With one or two objects, the performance is same.  After I instantiate 3, it slows a little, and 4 just completely wears it down.

I've read this article: http://www.4guysfromrolla.com/webtech/faq/Advanced/faq4.shtml

that says to avoid using session variables especially storing objects into them.  Well thats exactly what I'm doing.  My object has about 10 methods(~30 lines of code each) and 20 fields.

My question is, if I want to persist object in memory for each user session, how else could I store them on each postback if not in the session variable>?  I can't use application variable because thats shared and not thread safe.

what are my alternatives??


Static Variables in session


I am creating a static variable and adding to session.This variable has value that is user specific. Now I am getting a problem with this users are complaining that they are getting values that should be another users. It's like a mix up with session. Could this be because of static variable declaration?

Is there a way of creating an Ado.Net Entity Data Model filtered on a Session variables (C#)


I'm trying to customize correct displaying of dropdownlists so information shown in comboboxes is relevant to the kind of user logged on (maintaining referential integrity at data level)

e.g.: I have a user already logged on and depending on his profile I'd like to display to this user only the portion of the database that he would be allowed to see. That would mean that he might have acces to an specific subset of data, e.g.: businesstype = "3", loging level = "2", etc.

Is there a way of creating an Ado.Net Entity Data Model filtered on a Session variables as to maintain proper referential integrity at data level? So it means that the filtering must apply to all entities contained in the .edmx model at once.

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend