Search code examples
c#asp.nettwitter

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


Solution

  • 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.