从IIS 7.5服务器上运行的ASP.NET/C#
Web应用程序下载文件时,如何拦截正在响应中下载的PDF文件?该响应具有的application/pdf
和Content-Length
的10091
。使用http模块或http处理程序拦截C#中的文件下载?
目前,我已经写了HttpModule
重写方法:
public void Init(HttpApplication context){
context.BeginRequest+=Context_BeginRequest();
context.EndRequest+=Context_EndRequest();
}
private void Begin_Request(Object sender, EventArgs e){
// this function does not get called when downloading a file!
}
private void End_Request(Object sender, EventArgs e){
// this function does not get called when downloading a file!
}
哪些功能,我需要以截取文件下载响应,覆盖?
的web.config文件看起来像:
<system.webServer>
<modules runallManagedModulesForAllRequests="true">
<add name="MyMod.Module" type="MyMod.Module"/>
</modules>
</system.webServer>
你注册了模块吗? – Crowcoder
是的,该模块已注册,因为这两个功能都是在普通网络流量(即查看网页)上调用的。但是当我尝试下载文件的时候,这两个函数都没有被调用。 – user1068636
我不是这个级别的专家,但可能对该文件类型或所有静态文件的请求不通过aspnet管道。 – Crowcoder