简体   繁体   中英

httphandler intercept not working in IIS 7.0

I have an application done in .netframework 2.0 and trying to use an authentication handler in a security project, which is written in 3.5 framework. Also I m using IIS 7

Web.config of the application has the following entry

<system.webServer>
  <validation validateIntegratedModeConfiguration="false"/>
  <handlers  accessPolicy="Read, Write, Script, Execute">

      <add name="Pdfhandler" verb="*" path="/calderdale/*.pdf" type="NES.HiLo.Security.CalderDaleAuthenticationHandler, NES.HiLo.Security" preCondition="integratedMode" />
  </handlers>

 </system.webServer>

The code for CalderDaleAuthenticationHandler is

using System;
using System.Web;

namespace NES.HiLo.Security
{
    public class CalderDaleAuthenticationHandler : IHttpHandler
    {
        /// <summary>
        /// You will need to configure this handler in the web.config file of your 
        /// web and register it with IIS before being able to use it. For more information
        /// see the following link: http://go.microsoft.com/?linkid=8101007
        /// </summary>
        #region IHttpHandler Members
    public bool IsReusable
    {
        // Return false in case your Managed Handler cannot be reused for another request.
        // Usually this would be false in case you have some state information preserved per request.
        get { return false; }
    }

    public void ProcessRequest(HttpContext context)
    {
        //var application = (HttpApplication)sender;
        //var context = application.Context;

        HttpRequest request = context.Request;
        HttpResponse response = context.Response;


      // Check if the user is authenticated

    }

    #endregion
}

}

In my application I have a folder name calderdale and I have some pdf files. when I type in some thing like below to access the pdf file. I am expecting the control to go to handler, where I have set breakpoints. The control never goes to the handler. I appreciate any help.

http://local.knowledge.scot.nsh.uk/calderdale/abc.pdf

I used httphandlers to intercept the request. Then added a handler like this in web.config

<httpHandlers>
  <add verb="GET" path="calderdale/*.pdf"
   type="NES.HiLo.Security.CalderDaleAuthenticationHandler, NES.HiLo.Security" />
</httpHandlers>

After the above on IIS 7.0 I added the following handler from IIS Handlers section

<system.webServer>  
  <handlers>
    <add name="Calderdale Handler" path="calderdale/*.pdf"
     verb="GET" modules="IsapiModule"
     scriptProcessor="%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll"
     resourceType="Unspecified" requireAccess="Script"
     preCondition="classicMode,runtimeVersionv2.0,bitness32" />
  </handlers>
</system.webServer>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM