IHttpModule won't compile

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

    IHttpModule won't compile

    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><ht tpModules><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.Ini t and Dispose method
    that Implements IHttpModule.Dis pose.

    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.Visua lBasic
    Imports System
    Imports System.Collecti ons
    Imports System.Configur ation
    Imports System.Text
    Imports System.Threadin g
    Imports System.IO
    Imports System.Reflecti on
    Imports System.Web
    Imports System.Xml
    Imports System.Xml.XPat h


    'Namespace MyModule
    Public Class MyModule
    Implements IHttpModule, IConfigurationS ectionHandler

    Public Sub Dispose() Implements IHttpModule.Dis pose
    ' add clean-up code here if required
    End Sub
    Public Sub Init(ByVal app As HttpApplication ) Implements
    IHttpModule.Ini t
    ' 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

    #2
    Re: IHttpModule won't compile

    If this module code is in App_Code and has no namespace, type="MyModule" in
    <addis 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="MyModuleN amespace.MyModu le, MyModuleAssembl y"

    when your module has MyModuleNamespa ce namespace, its name is MyModule and
    it resides in MyModuleAssembl y.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




    "Eric Goforth" <eric.goforth@g mail.comwrote in message
    news:67ea9bff-96f3-427f-b4de-16ec880e7476@d4 5g2000hsc.googl egroups.com...
    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><ht tpModules><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.Ini t and Dispose method
    that Implements IHttpModule.Dis pose.
    >
    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.Visua lBasic
    Imports System
    Imports System.Collecti ons
    Imports System.Configur ation
    Imports System.Text
    Imports System.Threadin g
    Imports System.IO
    Imports System.Reflecti on
    Imports System.Web
    Imports System.Xml
    Imports System.Xml.XPat h
    >
    >
    'Namespace MyModule
    Public Class MyModule
    Implements IHttpModule, IConfigurationS ectionHandler
    >
    Public Sub Dispose() Implements IHttpModule.Dis pose
    ' add clean-up code here if required
    End Sub
    Public Sub Init(ByVal app As HttpApplication ) Implements
    IHttpModule.Ini t
    ' 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

    Comment

    Working...