Question

I have been struggling with this a while now.

I implemented a basic IHttpHandler with the following code and SESSION keeps being newed up:

namespace ClassLibrary1
{
    public class MyHandler : IHttpHandler, IRequiresSessionState
    {
        public bool IsReusable
        {
            get
            {
                return true;
            }
        }

        public void ProcessRequest(HttpContext context)
        {
            context.Response.Write(context.Session.SessionID + "</br>");
            context.Response.Write(DateTime.Now.TimeOfDay.ToString() + "</br>");
        }
    }
}

As you can see, very simple code. Then I simply create a folder c:\Inetpub\wwwroot\Test. I then add a bin folder and put my dll into the bin folder.

My web.config file then looks like this:

<configuration>
<system.webServer>
      <handlers>
        <add verb="*.x" path="*" name="MyHandler" type="ClassLibrary1.MyHandler" />
      </handlers>
    </system.webServer>
</configuration>

I then open IIS (IIS 7.0) and I have to right-click on the Test folder under default web site and click convert to application. This makes it a site.

I then go to a browser and i go to http://localhost/Test/

I then get something like this: fxnjswtkkzs1silahvpf5xun 09:48:52.9194609

If i press F5 or refresh the page, the session id changes. That is not supposed to happen.

I just cannot figure this out. And the funny thing is it did work yesterday. Can someone please help....

ps, same behaviour in firefox and ie

thanks in advance

Was it helpful?

Solution

Yes you are supposed to get a new SessionID every time, not only on your GenericHandler but also on a simple ASPX page UNLESS you access your Session object. Try this:

public void ProcessRequest (HttpContext context) {
    context.Response.ContentType = "text/plain";
    object o = context.Session["counter"];
    if (o == null)
        context.Session["counter"] = 1;
    else
        context.Session["counter"] = ((int) o) + 1;
    context.Response.Write(context.Session.SessionID + "\r\n");
    context.Response.Write(context.Session["counter"]);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top