IHttpModule won't compile

Discussion in 'ASP .Net' started by Eric Goforth, May 22, 2008.

  1. Eric Goforth

    Eric Goforth Guest

    Hello,

    I found a C# example on the web that used an httpmodule. I've
    translated it to VB.NET and the website compiles fine, but when I
    build the website the iHttpModule doesn't compile, I can't figure out
    why. I do have the following entry in my web.config file:

    <system.web><httpModules><add name="MyModule" type="MyModule.MyModule"/
    ></httpModules></system.web>


    My iHttpModule Class implements iHttpModule (of course). I also have
    an Init method that Implements IHttpModule.Init and Dispose method
    that Implements IHttpModule.Dispose.

    I think that my problem may be the syntax in the httpModules section
    of the web.config file. My site is structured like:

    /TestAppVB

    web.config

    myfile1.aspx

    myfile1.aspx.vb

    myfile2.aspx

    myfile2.aspx.vb

    /MyModule

    MyModule.vb

    MyModule.vb looks like:

    '--------------------------------------------------------------------------------------
    Imports Microsoft.VisualBasic
    Imports System
    Imports System.Collections
    Imports System.Configuration
    Imports System.Text
    Imports System.Threading
    Imports System.IO
    Imports System.Reflection
    Imports System.Web
    Imports System.Xml
    Imports System.Xml.XPath


    'Namespace MyModule
    Public Class MyModule
    Implements IHttpModule, IConfigurationSectionHandler

    Public Sub Dispose() Implements IHttpModule.Dispose
    ' add clean-up code here if required
    End Sub
    Public Sub Init(ByVal app As HttpApplication) Implements
    IHttpModule.Init
    ' add init code here if required
    End Sub

    End Class
    'End Namespace
    '--------------------------------------------------------------------------------------

    The code example that I found originally had this module in it's own
    namespace, but I commented that out to try to simplify things. I was
    thinking about trying to "flatten" the file structure and put MyModule
    in the same virtual folder as the .aspx and .aspx.vb files.

    Thanks,

    Eric
    Eric Goforth, May 22, 2008
    #1
    1. Advertising

  2. Eric Goforth

    Teemu Keiski Guest

    If this module code is in App_Code and has no namespace, type="MyModule" in
    <add> is enough. If you have web site project, it (the class file) cannot
    reside at same level with the pages etc since it won't get compiled. With
    web project the type is built into a dll, and you need to specify the
    assembly name (dll's name) in type attribute

    type="MyModuleNamespace.MyModule, MyModuleAssembly"

    when your module has MyModuleNamespace namespace, its name is MyModule and
    it resides in MyModuleAssembly.dll

    If you have the module in same dll with web project, it is the web
    application's single dll which you should specify into type.

    --
    Teemu Keiski
    AspInsider, ASP.NET MVP
    http://blogs.aspadvice.com/joteke
    http://teemukeiski.net


    "Eric Goforth" <> wrote in message
    news:...
    > Hello,
    >
    > I found a C# example on the web that used an httpmodule. I've
    > translated it to VB.NET and the website compiles fine, but when I
    > build the website the iHttpModule doesn't compile, I can't figure out
    > why. I do have the following entry in my web.config file:
    >
    > <system.web><httpModules><add name="MyModule" type="MyModule.MyModule"/
    >></httpModules></system.web>

    >
    > My iHttpModule Class implements iHttpModule (of course). I also have
    > an Init method that Implements IHttpModule.Init and Dispose method
    > that Implements IHttpModule.Dispose.
    >
    > I think that my problem may be the syntax in the httpModules section
    > of the web.config file. My site is structured like:
    >
    > /TestAppVB
    >
    > web.config
    >
    > myfile1.aspx
    >
    > myfile1.aspx.vb
    >
    > myfile2.aspx
    >
    > myfile2.aspx.vb
    >
    > /MyModule
    >
    > MyModule.vb
    >
    > MyModule.vb looks like:
    >
    > '--------------------------------------------------------------------------------------
    > Imports Microsoft.VisualBasic
    > Imports System
    > Imports System.Collections
    > Imports System.Configuration
    > Imports System.Text
    > Imports System.Threading
    > Imports System.IO
    > Imports System.Reflection
    > Imports System.Web
    > Imports System.Xml
    > Imports System.Xml.XPath
    >
    >
    > 'Namespace MyModule
    > Public Class MyModule
    > Implements IHttpModule, IConfigurationSectionHandler
    >
    > Public Sub Dispose() Implements IHttpModule.Dispose
    > ' add clean-up code here if required
    > End Sub
    > Public Sub Init(ByVal app As HttpApplication) Implements
    > IHttpModule.Init
    > ' add init code here if required
    > End Sub
    >
    > End Class
    > 'End Namespace
    > '--------------------------------------------------------------------------------------
    >
    > The code example that I found originally had this module in it's own
    > namespace, but I commented that out to try to simplify things. I was
    > thinking about trying to "flatten" the file structure and put MyModule
    > in the same virtual folder as the .aspx and .aspx.vb files.
    >
    > Thanks,
    >
    > Eric
    Teemu Keiski, May 22, 2008
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Duncan Godwin
    Replies:
    0
    Views:
    3,757
    Duncan Godwin
    Jun 25, 2003
  2. Steven Livingstone

    http pipline, ihttpmodule and filtering responses

    Steven Livingstone, Oct 16, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    444
  3. moid

    Front Controller / IHttpModule

    moid, Dec 25, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    468
  4. Replies:
    1
    Views:
    8,495
    Teemu Keiski
    Jan 22, 2004
  5. Nagaraj
    Replies:
    1
    Views:
    826
    Lionel B
    Mar 1, 2007
Loading...

Share This Page