c# - httphandler 拦截在 IIS 7.0 中不起作用

标签 c# asp.net iis

我有一个在 .netframework 2.0 中完成的应用程序,并试图在安全项目中使用身份验证处理程序,该项目是用 3.5 框架编写的。我也在使用 IIS 7

应用程序的 Web.config 具有以下条目

<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>

CalderDaleAuthenticationHandler 的代码是

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
}

在我的应用程序中,我有一个名为 calderdale 的文件夹,并且我有一些 pdf 文件。当我输入如下内容以访问 pdf 文件时。我希望控件转到我设置断点的处理程序。控件永远不会转到处理程序。感谢您的帮助。

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

最佳答案

我使用 httphandlers 来拦截请求。然后在 web.config 中添加这样的处理程序

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

在上面的 IIS 7.0 之后,我从 IIS 处理程序部分添加了以下处理程序

<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>

关于c# - httphandler 拦截在 IIS 7.0 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12973404/

相关文章:

c# - 无法在单元测试中访问已处置的对象

c# - 用字符串拆分字符串时出错

asp.net - hotcake commerce 自定义付款方式不起作用

c# - 在 C# 中,将 List<T> 转换为 SortedDictionary<string, T> 的最佳方法是什么?

c# - 在CommandLineTool中显示ObservableCollection项目

asp.net - 使用 css 自定义 web.sitemap 的默认菜单样式

iis - 如何增加失败请求日志的最大大小?

iis - 防止浏览器提示输入 IIS 应用程序的客户端证书

asp.net - 将 Web 应用程序部署到 IIS 后的 JavaScript

c# - 将数据(消息)发送到服务器的最佳(广泛接受)方式是什么