custom http handler -- not reaching the session

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?
 
D

Davide Vernole [MVP]

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
 
M

mortb

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
 
D

Davide Vernole [MVP]

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 ?
 
M

mortb

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
 
D

Davide Vernole [MVP]

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

mortb

Doh, should've thought of that....
Thank you very much for your time!

cheers,
mortb
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top