Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

If I host an ASP.NET page with:

<%@ Page Language="C#" %>

<!DOCTYPE html>    
<script runat="server">

    protected void btn_Click(object sender, EventArgs e)
    {
        lbl.Text = HttpContext.Current.Session["a"] == null ? 
                       "null" : 
                       HttpContext.Current.Session["a"].ToString();
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            HttpContext.Current.Session["a"] = "A";
            lbl.Text = "assigned Session Variable";
        }
    }
</script>

<html>
<head>
    <title>Testing Sessions</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button ID="btn" runat="server" Text="reload" OnClick="btn_Click" />
        <hr />
        <asp:Label ID="lbl" runat="server" />
    </div>
    </form>
</body>
</html>

on the first run I do get the assigned Session Variable text, but upon click the Session object is always null

Id there an option I need to turn on/off to use the normal Session Variables ?

works fine on IIS 6.0 and Cassini (under VS 2008 and 2010).

I'm starting to be without ideas on what's going on :o(

Any help is greatly appreciated!


the process of the example page above

alt text

alt text


More tests shows that this only happens in IE (ie8 in this case), Firefox, Safari, Opera, Chrome they all give the correct "answer"

alt text


check the screen cast of the situation

share|improve this question
add comment

5 Answers

Traditional session state requires cookies to be enabled for the site in question. Is it at all possible you have Internet Explorer set to block the cookie coming from the server, and the other browsers not set that way? That would explain the difference in behavior. You should be able to use Fiddler (cf. http://www.fiddler2.com/fiddler2/) to watch the HTTP traffic between IE and the server, and see if IE is sending the cookie back to the server. I strongly suspect the answer is "no".

You can potentially set cookieless sessions (e. g. http://msdn.microsoft.com/en-us/library/ms972429.aspx) in your web.config file to confirm this as well; if cookieless works, then there ya go.

share|improve this answer
    
it does all the time: Response sets a cookie: Set-Cookie: ASP.NET_SessionId=21rl2re24e0d2h3543yel245; path=/; HttpOnly - this is really very strange, even outsite the server, in all IE, the behavior is the same... and no yellow message as you can see by the screen cast. –  balexandre Sep 7 '10 at 13:20
    
for what I read cookieless State works on .net 4, and all examples point to SQL Server (like SQL Session State) and I don't want that. This is a simple "web application" and works fine under Windows 2003 Server and IE 6... Session problem is on Windows 2008 R2 and IE8 :( –  balexandre Sep 7 '10 at 13:27
    
cookieless has been in .NET since 1.0, it's not a 4.0 feature. And it has nothing to do with SQL Server. You're showing the response cookie, not the request cookie, which is what you need to look for - see if IE is sending the cookie back to the server on the next request. I don't know what "no yellow message" means in this case. –  MikeBaz Sep 7 '10 at 15:42
add comment
up vote 0 down vote accepted

If anyone find this "bug", do a simple thing to resolve it.

  • delete the virtual application
  • create a new virtual application (can have the same name as previously)
share|improve this answer
add comment

Had the same issue at a customer. Removing and adding the application won't solve the issue in this case. The trick is: Replace or remove the underscore in the url!

share|improve this answer
add comment

You must change your url par_2008_64 in par200864 because in explorer the underscore doesn't work and the session becomes null

share|improve this answer
add comment

to balexandre

Not true. I have brand new web app set up not as virtual directory but individual web site. same story on 2008 R2 does not matter if it is new or existing apps.

share|improve this answer
    
Don't write comments as answers. Down-voted. –  PaparazzoKid Dec 14 '13 at 23:57
    
Not a helpful answer. –  Andrew Schulman Dec 15 '13 at 3:23
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.