HttpModule not compiling

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • tshad

    #1

    HttpModule not compiling

    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\H ttpModules\Http Modules.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\H ttpModules\Http Modules.cs(9): The type or namespace name
    'HttpApplicatio n' 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 HttpModuleExamp les
    {
    public class CustomHttpModul e : IHttpModule
    {
    //IHttpModule Members
    public void Init(HttpApplic ation httpApp)
    {
    httpApp.BeginRe quest += new EventHandler(th is.OnBeginReque st);
    httpApp.EndRequ est += new EventHandler(th is.OnEndRequest );
    }
    public void Displose()
    {
    //Usually nothing has to happen here
    }

    // Event Handlers
    public void OnBeginRequest( object o, EventArgs ea)
    {
    HttpApplication httpApp = (HttpApplicatio n) o;
    HttpContext ctx = HttpContext.Cur rent;
    ctx.Response.Wr ite("Beginning Request <br>");
    }

    public void OnEndRequest(ob ject o, EventArgs ea)
    {
    HttpApplication httpApp = (HttpApplicatio n) o;
    HttpContext ctx = HttpContext.Cur rent;
    ctx.Response.Wr ite("Ending Request <br>");
    }
    }
    }
    *************** *************** *************** ************

    Thanks,

    Tom


  • Peter Bromberg [C# MVP]

    #2
    RE: HttpModule not compiling

    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
    --
    Co-founder, Eggheadcafe.com developer portal:

    UnBlog:





    "tshad" wrote:
    [color=blue]
    > 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\H ttpModules\Http Modules.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\H ttpModules\Http Modules.cs(9): The type or namespace name
    > 'HttpApplicatio n' 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 HttpModuleExamp les
    > {
    > public class CustomHttpModul e : IHttpModule
    > {
    > //IHttpModule Members
    > public void Init(HttpApplic ation httpApp)
    > {
    > httpApp.BeginRe quest += new EventHandler(th is.OnBeginReque st);
    > httpApp.EndRequ est += new EventHandler(th is.OnEndRequest );
    > }
    > public void Displose()
    > {
    > //Usually nothing has to happen here
    > }
    >
    > // Event Handlers
    > public void OnBeginRequest( object o, EventArgs ea)
    > {
    > HttpApplication httpApp = (HttpApplicatio n) o;
    > HttpContext ctx = HttpContext.Cur rent;
    > ctx.Response.Wr ite("Beginning Request <br>");
    > }
    >
    > public void OnEndRequest(ob ject o, EventArgs ea)
    > {
    > HttpApplication httpApp = (HttpApplicatio n) o;
    > HttpContext ctx = HttpContext.Cur rent;
    > ctx.Response.Wr ite("Ending Request <br>");
    > }
    > }
    > }
    > *************** *************** *************** ************
    >
    > Thanks,
    >
    > Tom
    >
    >
    >[/color]

    Comment

    • tshad

      #3
      Re: HttpModule not compiling

      "Peter Bromberg [C# MVP]" <pbromberg@yaho o.nospammin.com > wrote in message
      news:82907F85-4699-41DF-9CF4-091C762A75F6@mi crosoft.com...[color=blue]
      > 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.[/color]

      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[color=blue]
      > Peter
      > --
      > Co-founder, Eggheadcafe.com developer portal:
      > http://www.eggheadcafe.com
      > UnBlog:
      > http://petesbloggerama.blogspot.com
      >
      >
      >
      >
      > "tshad" wrote:
      >[color=green]
      >> 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\H ttpModules\Http Modules.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\H ttpModules\Http Modules.cs(9): The type or namespace name
      >> 'HttpApplicatio n' 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 HttpModuleExamp les
      >> {
      >> public class CustomHttpModul e : IHttpModule
      >> {
      >> //IHttpModule Members
      >> public void Init(HttpApplic ation httpApp)
      >> {
      >> httpApp.BeginRe quest += new EventHandler(th is.OnBeginReque st);
      >> httpApp.EndRequ est += new EventHandler(th is.OnEndRequest );
      >> }
      >> public void Displose()
      >> {
      >> //Usually nothing has to happen here
      >> }
      >>
      >> // Event Handlers
      >> public void OnBeginRequest( object o, EventArgs ea)
      >> {
      >> HttpApplication httpApp = (HttpApplicatio n) o;
      >> HttpContext ctx = HttpContext.Cur rent;
      >> ctx.Response.Wr ite("Beginning Request <br>");
      >> }
      >>
      >> public void OnEndRequest(ob ject o, EventArgs ea)
      >> {
      >> HttpApplication httpApp = (HttpApplicatio n) o;
      >> HttpContext ctx = HttpContext.Cur rent;
      >> ctx.Response.Wr ite("Ending Request <br>");
      >> }
      >> }
      >> }
      >> *************** *************** *************** ************
      >>
      >> Thanks,
      >>
      >> Tom
      >>
      >>
      >>[/color][/color]


      Comment

      Working...