Sandhurst
Sandhurst

Reputation: 1180

Why HttpContext.Current.Session is changing evertime I visit the same page ASP.Net

Here's the scenario

I have a page lets say login.aspx having a button called login, on click event of that button when I check for the SessionID its shows a specific value for example "A"

Now I am making a call to some external page and that page then calls this page again.

for instance once I click login button I call a twitter app and when user authorizes it, I am redirected back to the same page, but now when I am accessing the SessionID its a new ID.

I have no idea why this is happening, I just want to have the same SessionID

Upvotes: 1

Views: 1501

Answers (3)

Caizi
Caizi

Reputation: 1

In our case, the issue was caused by the AppPools setting 'Maximum Worker Processes' to 0.

By default, this should be set to 1 to prevent opening new server processes with new sessions based on the current load.

Upvotes: 0

Steve Morgan
Steve Morgan

Reputation: 13091

You don't have multiple web servers, do you?

If so, and if you're not using a shared session state provider, you'd tend to see this kind of behaviour.

Edit.

OK, next question...

Is the URL that the Twitter authorisation is returning to using exactly the same domain name?

For example, if your application is running on http://127.0.0.1:1234/ and the return URL is http://localhost:1234/ ?

Edit2: Yes?

When you are redirected back from the Twitter app on 127.0.0.1, the ASP.NET session cookie isn't being passed back to the web server because the domain is different.

You need the domain that the app is running under to match the Twitter callback URL.

Reconfigure the Twitter callback URL to localhost:1234 and I think you should be OK.

Upvotes: 1

Wyatt Barnett
Wyatt Barnett

Reputation: 15663

Are you adding any data to the session? You need to do so for the session ID to "stick".

Upvotes: 2

Related Questions