custom http handler -- not reaching the session

  • Thread starter Thread starter mortb
  • Start date Start date
M

mortb

I have written a custom http handler and added it to the web.config file

<httpHandlers>
<add verb="GET" path="ITImageService.axd"
type="ITImageService.ITImageGetter,ITImageService" />
</httpHandlers>

The code for the handler looks like:

public bool IsReusable { get { return true; } }
public void ProcessRequest(HttpContext context)
{
if(context.Session == null) { context.Response.Write("Session is
null"); return
}

A page adds some variables to the session and calls this handler url
http://localhost/myApp/ITImageService.axd
The handler writes "session is null" when there in fact is something in the
session.Why does the handler not reach teh session?
 
mortb said:
I have written a custom http handler and added it to the web.config
file

<httpHandlers>
<add verb="GET" path="ITImageService.axd"
type="ITImageService.ITImageGetter,ITImageService" />
</httpHandlers>

The code for the handler looks like:

public bool IsReusable { get { return true; } }
public void ProcessRequest(HttpContext context)
{
if(context.Session == null) { context.Response.Write("Session
is null"); return
}

A page adds some variables to the session and calls this handler url
http://localhost/myApp/ITImageService.axd
The handler writes "session is null" when there in fact is something
in the session.Why does the handler not reach teh session?

Try to Inherith from IRequiresSessionState. Your HttpHandler class could be
like this:

public class MyHttpHandler: IHttpHandler , IRequiresSessionState
{
//class implementation
}

Read this to more info:
http://msdn.microsoft.com/library/d...ssionStateIRequiresSessionStateClassTopic.asp
 
Two more questions:

* Do I have access to the cache (like context.Cache etc) or do I need to
inherit for that also?
* How do I debug my httpHandler? VisualStudio does not step into the code
when run.

cheers,
mortb
 
mortb said:
Two more questions:

* Do I have access to the cache (like context.Cache etc) or do I need
to inherit for that also?

Yes, you can without any other interface or class. Do that using the
HttpContext context object inside the ProcessRequest function:

MyObject object = (MyObject)context.Cache["MyCachedObject"]
* How do I debug my httpHandler? VisualStudio does not step into the
code when run.


You can debug as usual. Are you sure to be in debug mode ?
 
You can debug as usual. Are you sure to be in debug mode ?

Yes I am in debug mode
I step into the code on the pages but not into this http handler
It is located in another assembly, but so are other class libraries that I
use in my applicaiton and I am able to debug them.

/mortb
 
mortb said:
Yes I am in debug mode
I step into the code on the pages but not into this http handler
It is located in another assembly, but so are other class libraries
that I use in my applicaiton and I am able to debug them.

Refer the project of your assembly insted of the assemby dll in your main
project. This should resolve the problem.
 
Back
Top