2012-10-19 31 views
2

我在.netframework 2.0中完成了一个应用程序,并试图在3.5框架中编写的安全项目中使用身份验证处理程序。还我米使用IIS 7httphandler拦截在IIS 7.0中不起作用

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

回答

0

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