httpmodule not being invoked

Discussion in 'ASP.NET / ASP.NET Core' started by kurtrichard, Jan 6, 2009.

  1. Hi all

    I wonder if you can help. I have written an httpmodule that controls access to certain folder in my application. This works fine on my development machine, but it seems that the httpmodule is not being invoked on the published version. The code outline is below - but as I say this works fine in development... so maybe it is just a web.config issue.




    Imports Microsoft.VisualBasic
    Imports System.Web

    Public Class HttpModule
    Implements IHttpModule

    Public Sub Dispose() Implements System.Web.IHttpModule.Dispose
    'Cleanup
    End Sub

    Public Sub Init(ByVal application As HttpApplication) Implements IHttpModule.Init
    AddHandler application.AuthenticateRequest, AddressOf Me.Application_AuthenticateRequest
    End Sub

    Private Sub Application_AuthenticateRequest(ByVal source As Object, ByVal e As EventArgs)
    Dim context As HttpContext = HttpContext.Current
    Dim db As New DataClassesDataContext

    'Authentication check for E:CO
    If context.Request.Path.ToString.IndexOf("ECO_papers") <> -1 Then

    ...

    End If

    'Authentication check for eBooks
    If context.Request.Path.ToString.IndexOf("eBooks") <> -1 Then

    ...

    End If
    db.Dispose()
    End Sub

    and the following entry is added to the web.config file in the application root:

     
  2. Bruce

    Bruce DiscountASP.NET Staff

    code looks fine to me.. what do you mean by it doesn't invoke? does it bomb out w/ an error?

    Bruce

    DiscountASP.NET
    www.DiscountASP.NET
     
  3. Hi Bruce


    It now seems that it is only links that point to .pdf files that are affected (as these are the only ones that trigger decision logic in the httpmodule), nothing was happening because IIS6 does not process .pdf links through the aspnet engine. So technical support have added a script map for .pdf so that they get processed by the aspnet engine.


    However, now there is a new problem. Although it seems that all the decision branches of the httpmodule are being exercised whenever a user is 'allowed' through to view the .pdf file IE throw an error:
    Internet Explorer cannot display the webpage
    Any thoughts?

    This all works fine with IIS7 which doesn't need to script mapping to handle links to .pdf files. There is something about how IIS6 processes these links to .pdf files that causes problems.

    Kind regards, Kurt
     
  4. An update:


    It now seems that any calls to .pdf files, such as:


    http://iscepublishing.com/ECO/ECo_Other/Issue_6_1-2_3_ED.pdf


    leads to the same error... so this is not a problem related to the httpmodule... but something to do with how IIS6 processes such calls. Such calls need to be processed by the aspnet engine (which requires a script map), but there is a glitch somewhere in the pipeline... I should probably move over to a different topic thread...


    Any thoughts?


    Thanks as always, Kurt
     
  5. Hi Bruce


    Are you saying that you opened the PDF OK? If so, do you have any thoughts on why I would not be able to open it with IE7?


    Many thanks, Kurt
     
  6. OK so I finally have the answer. The initial problem is that IIS6 does not support a fully integrated request pipeline and so links ending with non asp.net suffixes (such as .pdf) have to be explicitly mapped to the aspnet isapi if you want to use something like httpmodule to control access to those files. Discountasp technical support therefore added a script map so that .pdf would be processed by aspnet. Unfortunately this screwed-up even direct accesses to .pdf files. What they should of done is add a wildcard map instead. Once this was done everything worked fine. I don't understand enough to say why the script map made things worse, whereas the wildcard map solved the original problem without introducing any new onces.


    Bye for now, Kurt
     
  7. Bruce

    Bruce DiscountASP.NET Staff

Share This Page