HttpModule not compiling

T

tshad

I am trying to build an HttpModule and am building just the skeleton part of
the program in VS 2003 and am getting a couple of errors. But this is how I
have seen the file built in a couple of different places.

The errors are:
C:\VSProjects\HttpModules\HttpModules.cs(6): The type or namespace name
'IHttpModule' could not be found (are you missing a using directive or an
assembly reference?)

and

C:\VSProjects\HttpModules\HttpModules.cs(9): The type or namespace name
'HttpApplication' could not be found (are you missing a using directive or
an assembly reference?)

I am building this as a class library and the Using clauses are the same as
I have seen elsewhere. Do I need something else (I assume I do)?

*********************************************************
using System;
using System.Web;

namespace HttpModuleExamples
{
public class CustomHttpModule : IHttpModule
{
//IHttpModule Members
public void Init(HttpApplication httpApp)
{
httpApp.BeginRequest += new EventHandler(this.OnBeginRequest);
httpApp.EndRequest += new EventHandler(this.OnEndRequest);
}
public void Displose()
{
//Usually nothing has to happen here
}

// Event Handlers
public void OnBeginRequest(object o, EventArgs ea)
{
HttpApplication httpApp = (HttpApplication) o;
HttpContext ctx = HttpContext.Current;
ctx.Response.Write("Beginning Request <br>");
}

public void OnEndRequest(object o, EventArgs ea)
{
HttpApplication httpApp = (HttpApplication) o;
HttpContext ctx = HttpContext.Current;
ctx.Response.Write("Ending Request <br>");
}
}
}
*********************************************************

Thanks,

Tom
 
G

Guest

Tshad,
IHttpModule interface lives in System.Web. It's not sufficient just to put a
"using" directive at the top of your class. If the assembly is not in the
default assemblies loaded for the project type, you need to specifically add
a reference to it.
Peter
 
T

tshad

Peter Bromberg said:
Tshad,
IHttpModule interface lives in System.Web. It's not sufficient just to put
a
"using" directive at the top of your class. If the assembly is not in the
default assemblies loaded for the project type, you need to specifically
add
a reference to it.

That did it.

I assumed that since it worked fine for my Web Applications, it would work
for my Classes. But the Web Applications assume that it will need that
library and a class doesn't necessarily know that, I would guess.

Thanks,

Tom
 

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

Top