0

I have a solution with 2 projects : Core and Web. In the Core, I manage session I do something and I call this method :

public void SetLog()
{
    HttpContext.Current.Session["Logged"] = true;
}

That's work.

When I change page (I use the ASP.NET 4.0 default template for testing), I click on the "About" link and I call this method :

public bool IsLogged()
{
    if (HttpContext.Current.Session["Logged"] == null)
        return false;

    return true;
}

On the About page, Session are null, normal ? how solve this ?

Thanks,

2
  • Did you recompile in between? Is Core a web application? Commented Jun 20, 2012 at 6:21
  • Further to @DarinDimitrov's comments are both pages running under the same website? Commented Jun 20, 2012 at 6:24

1 Answer 1

1

I suspect that you have 2 web applications: Core and Web hosted on 2 different domains: http://localhost:1234 and http://localhost:5678. You seem to be setting the session variable inside the first web application but this session is only about the first application. As soon as you leave this application the other has a completely distinct session. Remember that sessions cannot be shared between ASP.NET applications. There are workarounds for this but out of the box it doesn't work.

Sign up to request clarification or add additional context in comments.

4 Comments

Core is a "Class library". I start the application, on the default page, I do the "SetLog()" and direclty after a IsLogged() and IsLogged is true. I click on the "About" page, in the Page_Load, I call IsLogged() and the session is null.
That's very strange and shouldn't normally happen. Do you have cookies enabled in your web browser?
"Allow local data to be set" in Google chrome, then yes, it is.
And can you see the session cookie being sent in the request when you use the developer tools?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.