Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Session Variables and Cookies not Working in ASP.NET???

Status
Not open for further replies.

C0PP3R

Programmer
Jun 27, 2002
64
CA
I'm hosting an intranet on the latest version of IIS running on Win 2K server. I am hosting ASP.net applications but Session variables and cookies do not work ?

Any suggestions, When I test the pages on my local host machine (I used a seperate machine with local IIS for development at first, but will use the actual from now on) and session variables and cookies work.

Help!

Thanks all,

Copper
 
First, check to make sure to "domain" of the cookie is correct (I had this problem :)
Second, do not use frames! frames came from the devil himself! (had that issue too)
As far as the session goes, what method are you using InProc, StateServer etc.
 
Ok, I'm new to IIS, and my network manager is on holidays, but I have access ot the server and what not.

How do I check the domain of the cookie or session, I'm not using frames, I will head your advice

I'm not sure what you mean by method, define InProc, Stateserver, etc..?

Thanks
 
Sorry about that, I was assuming you use ASP.NET. the domain of the cookie is set by the application that issues the cookie so, can you tell me what the application is built with (Asp,Net, ColdFusion, etc.)
I will be able to help you more once I know what you use.
 
Ok, I am using ASP.net, my apologies, i should have specified that in the post
 
In the "Home Directory" of the application you should find a file called "web.config", open that file and find "sessionState", this is the application's setting for controling the session objects.
Here is a good reference for you:

Let me know if you're still having problems, good hunting :)
 
Well I checked that, and I'm trying to keep the session and or cookie local to the machine that is accessing the page. I played with the settings but to no avail, My Web.config code for the session is as follows: (note, pretty much default it what I believe i need)

<sessionState
mode=&quot;InProc&quot;
stateConnectionString=&quot;tcpip=127.0.0.1:42424&quot;
sqlConnectionString=&quot;data source=127.0.0.1;user id=sa;password=&quot;
cookieless=&quot;false&quot;
timeout=&quot;20&quot;
/>

Thanks allot!
 
&quot;InProc&quot; means the session object is controlled by the same process that run Asp.NET which mean that if the process is restarted for whatever reason (error or what not) the session is lost, try to check the machine's event log maybe there are some errors there.
If the log does not show any errors for Asp.NET check your code, that is the only other thing that could be wrong.
You can post a sample of your code that creates the session and then uses the session to retrieve data from it and I can look it over for you.
 
Ok, here is the code I use for setting and getting the session variables:

Set:
Session.Add(&quot;BeginDate&quot;, txtBeginDate.Text)

Session.Add(&quot;EndDate&quot;, txtEndDate.Text)

Session.Add(&quot;Shop&quot;, cboShop.SelectedItem.Text)

Session.Add(&quot;Exchange&quot;, cboExchange.SelectedItem.Text)


Get:
lblMessage.Text = Session.Item(&quot;Begindate&quot;) & vbCr & Session.Item(&quot;Enddate&quot;) & vbCr & _
' Session.Item(&quot;Shop&quot;) & vbCr & Session.Item(&quot;Exchange&quot;)


Here's the code I use to set and get my cookie

Set:
Dim MyCookie As New HttpCookie(&quot;Test&quot;)

MyCookie.Domain = &quot;PHOENIX_DOMAIN&quot;

MyCookie.Path = &quot;C:\WINNT\Profiles\andrewt\Cookies\&quot;

MyCookie.Value = &quot;TestingCookie&quot;

Dim dt As DateTime = DateTime.Now

Dim ts As New TimeSpan(1, 0, 0)

MyCookie.Expires = dt.Add(ts)

Response.Cookies.Add(MyCookie)

Get:

lblMessage.Text = Request.Cookies(&quot;Test&quot;).Value
 
And I wasn't able to find anything within the event viewer on my web server.
 
As far as the cookies go, try commenting out these two lines:

MyCookie.Domain = &quot;PHOENIX_DOMAIN&quot;
MyCookie.Path = &quot;C:\WINNT\Profiles\andrewt\Cookies\&quot;

by the way the &quot;PATH&quot; is not suppose to be a local path, it will be too long to explain here (see the help file for further explanation)

see if that works for you and let me know.
 
On second thought try replacing your code to issue the cookie with this (it runs alittle better)

Dim MyCookie As New HttpCookie(&quot;Test&quot;)
MyCookie.Value = &quot;TestingCookie&quot;
MyCookie.Expires = Now.AddHours(1)
Response.Cookies.Add(MyCookie)

Let me know how it goes.
 
k, i tried your cookie code, same thing, I get the error that says object not set to an instance of an object because it can't find the cookie i created. I'm a little lost at this point, but I have one quick question, that link you ent me about the session state, How do I make sure that ASP Session is running on my web server?
 
There are two ways:
You can have the session state set to &quot;InProc&quot; like you have right now, the Asp.NET process (running on your web server) will take care of the rest.
The second way is StateServer that is a service (look under the &quot;services&quot; in Administrative tools) the service is called &quot;ASP.NET State Service&quot; start it and set it to start automaticaly (so it starts with windows).
To use state server you need this configuration in web.config:

<sessionState
mode=&quot;StateServer&quot;
stateConnectionString=&quot;tcpip=localhost:42424&quot;
/>

 
Hmmm....ok, I got an error so I'm checking the value of a reg key on my Web server to allow remote connections, the other is making sure the ports are the same on the server and the client. I don't know how to do that, ideas?

And thanks, your help so far has been awesome, muchly appreciated
 
I'm not sure how to do that, sorry.
What version of the .Net Framework are you using?
 
Version 1.1, it's wierd, I'm using Basic Authentication on my web server, because it allows me to access my network resources with aspx pages because my network doesn't have active dir set up.

When I host on my local machine the session and cookies work fine, but once i use my actual web server it doesn't work, blah.....getting frustrated, oh well, gotta keep at er.
 
This is a long shot but might be worth the try.
Open &quot;Internet Services Manager&quot; (on the web server)
Right Click on your site (Default Web Site I assume) and select &quot;Properties...&quot;
Go to the &quot;Home Directory&quot; tab
Click the &quot;Configure...&quot; button
Go to the &quot;app Options&quot; Tab
Make sure &quot;Enable Session State&quot; is checked and give it a session time out value of 20 minutes (if it's not already in there.
You can try comparing option between you local web server's configuration and the live one.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top