We are excited to announce that the IIS.NET Forums are moving to the new Microsoft Q&A experience. Learn more >

Adding HttpModule dll in IIS 6.0 [Answered]RSS

8 replies

Last post Aug 13, 2008 04:42 PM by jabailo

  • Adding HttpModule dll in IIS 6.0

    Jul 20, 2007 12:23 AM|surenb|LINK

    Hi,

    I am a newbie at this.

    I have created a class library project in asp.net 2.0 which implements IHttpModule. I tried to add this dll in windows 2003 IIS 6.0 using wildcard application mapping (with the "verify that file exist" unchecked) by following the instructions given in the link below

     http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/5c5ae5e0-f4f9-44b0-a743-f4c3a5ff68ec.mspx?mfr=true

    I received an Error 404, so I followed the instructions given by http://support.microsoft.com/kb/315122 and added the web service extensions.

    Now I am getting an "There is a problem with the page you are trying to reach and it cannot be displayed". That is it says Http 500 Internal Server Error.

    I need to add this dll in the server to protect a somepage.aspx. It's a third party developed aspx files where I cannot really add anything to their web.config file. So Instead of using ISAPI filters(Which require knowledge of C++), we decided to do it by HttpModule and then add the dll.

    Can anyone please tell me this can be done? If so how to avoid theHttp 500 Internal Server Error?

    I am really at my wit's end. Can someone please help me............

    Suren

  • Re: Adding HttpModule dll in IIS 6.0

    Jul 20, 2007 02:51 AM|mvolo|LINK

    Suren,

    You cannot map a managed DLL to be a wildcard extension in IIS - the wildcard extension DLL must be a native ISAPI extension.  What you need to do is map ASPNET_ISAPI.DLL (the one that is mapped to .aspx) as the wildcard extension.

    Then, all requests to the url and below that has the wildcard extension will be passed through ASP.NET, where your module will have a chance to do its work.  For an example of doing this, you can check our my blog post here, where I do it to run my LeechGuard ASP.NET modules for all IIS content: http://mvolo.com/blogs/serverside/archive/2006/11/10/Stopping-hot_2D00_linking-with-IIS-and-ASP.NET.aspx.

    Read the "Enabling LeechGuard to protect images on IIS6" part.


    Thanks,

    Mike Volodarsky

    Program Manager
    IIS Core Server
    Visit mvolo.com for more inside information on IIS7, IIS and ASP.NET

    Mike V.
    CTO at LeanSentry, Former IIS PM

    Expert guides:
    1. Restart IIS correctly
    2. Expert guide to IIS logs
    3. Tune IIS thread pool
  • Re: Adding HttpModule dll in IIS 6.0

    Jul 20, 2007 08:06 AM|tomkmvp|LINK

    Here's a generic reference on MSDN on how to create and configure an HttpModule ...
    http://msdn.microsoft.com/en-us/library/tfd6k449.aspx

  • Re: Adding HttpModule dll in IIS 6.0

    Jul 20, 2007 09:06 AM|surenb|LINK

    Hi Mike Volodarsky,

    Thanks a lot for explaining it very clearly and also for the link.

    Here is what I have to do, I have a page "page1.aspx", which has a link that takes me to "page2.aspx".This page2.aspx is a third party application where I cannot insert or add anything in the web.config file of this page.

    So we wrote a HttpModule dll to check the urlrefferer of the page2.aspx, if it exist it will be displayed or else it will be redirected page2.aspx

    Here is my HttpModule

    Namespace SecurityModules
           Public Class CustomURLModule
            Implements IHttpModule

            Public Sub Dispose() Implements System.Web.IHttpModule.Dispose

            End Sub

            Public Sub Init(ByVal context As System.Web.HttpApplication) Implements System.Web.IHttpModule.Init
                AddHandler context.BeginRequest, AddressOf onBeginRequest


                AddHandler context.EndRequest, AddressOf onEndRequest
            End Sub

            Public Sub onBeginRequest(ByVal sender As Object, ByVal e As EventArgs)

                Dim app As HttpApplication
                app = CType(sender, HttpApplication)

                If System.Web.HttpContext.Current.Request.Url.AbsolutePath = "http://localhost/Mypage/page2.aspx" Then
                    If System.Web.HttpContext.Current.Request.UrlReferrer Is Nothing Then

                        System.Web.HttpContext.Current.Response.Redirect("http://localhost/TestPage/page1.aspx")

                    End If
               End Sub.

    So I tried doing according to the instructions in blog, Just by adding the dll in the "bin" folder of the application and mapping the ASPNET_ISAPI.DLL as wildcard application.It is not working. Am I missing something?

    Suren

  • Re: Adding HttpModule dll in IIS 6.0

    Jul 20, 2007 10:46 PM|mvolo|LINK

    Suren,

    Those instructions are for configuring ASP.NET to be the wildcard extension, so that ASP.NET processes all requests to your application.  From your module code, I see that you dont actually need this.  Since you module only needs to intercept requests to page2.aspx, an ASP.NET page, you can simply add your module and it will work.

    Now, for the add the module part (which is required to load an IHttpModule to your ASP.NET application whether or not you are setting up the wildcard extension), you need to add your module to the web.config for your application as follows:

    <configuration>

    <system.web>
      <httpModules>
          <add name="YourModule" type="SecurityModules.CustomURLModule" />
      </httpModules>
    </system.web>

    </configuration>

    If your web.config already exists, place that config between the existing <configuration> tags.

    Thanks,

    Mike Volodarsky

    Program Manager
    IIS Core Server
    Visit mvolo.com for more inside information on IIS7, IIS and ASP.NET

    Mike V.
    CTO at LeanSentry, Former IIS PM

    Expert guides:
    1. Restart IIS correctly
    2. Expert guide to IIS logs
    3. Tune IIS thread pool
  • Re: Adding HttpModule dll in IIS 6.0

    Jul 21, 2007 10:02 PM|surenb|LINK

    Thanks a lot Mike.

    That really helped a lot. Now may be I will look more into ISAPI filter because I cannot really add that part in web.config of page2.aspx

    Suren 

     

  • Re: Adding HttpModule dll in IIS 6.0

    Jul 21, 2007 10:29 PM|mvolo|LINK

    Suren,

    You can also add the modules globally on the server without touching the web.config for your application.

    You can use a <location> tag to apply the <httpModules> configuration to your application, but set it in root web.config (in the framework directory).

    An ISAPI filter is much, much more painful of a solutuon to this problem than should be necessary.

    Thanks,


    Mike Volodarsky

    Program Manager
    IIS Core Server
    Visit mvolo.com for more inside information on IIS7, IIS and ASP.NET

    Mike V.
    CTO at LeanSentry, Former IIS PM

    Expert guides:
    1. Restart IIS correctly
    2. Expert guide to IIS logs
    3. Tune IIS thread pool
  • Re: Adding HttpModule dll in IIS 6.0

    Jul 23, 2007 09:10 AM|surenb|LINK

    Hi Mike,

    Thanks. Let me work on it and if I have any doubt, I will come back.

    If it solves my problem, I will put it on the post too.

    Really thanks for your advice.

    Suren 

     

     

     

  • Re: Adding HttpModule dll in IIS 6.0

    Aug 13, 2008 04:42 PM|jabailo|LINK

    I am trying to add a URL Write HttpModule.   I use the Wildcard Application Mapping to point back to aspnet_isapi.dll (.net 2.0).

     It works fine as a virtual directory -- but not at the root, web site, level.

     Can you suggest why?

     

    John A. Bailo