简体   繁体   English

在asp.net中捕获请求静态文件

[英]Capture request static file in asp.net

How can I capture and handle static file requests with asp.net? 如何使用asp.net捕获和处理静态文件请求?

I've tried the "IModule" and "Global.asax" with BeginRequest but the request is not captured. 我已尝试使用BeginRequest的“IModule”和“Global.asax”,但未捕获请求。

Is there some setting in IIS to direct some Component (IModule / Handler / Global.asax / DLL) in asp.net? IIS中是否有一些设置可以在asp.net中引导某些组件(IModule / Handler / Global.asax / DLL)?

Or some way to direct requests to some DLL made with C #? 或者某种方式将请求引导到使用C#制作的某些DLL?

For example: "get http://localhost/myapp/report/report1.html " 例如:“获取http://localhost/myapp/report/report1.html

How can I capture this request? 我该如何捕获此请求?

I could not do, get in asp.net. 我做不到,进入asp.net。

I want to be able to check the permission, and can handle the file, and handle the response. 我希望能够检查权限,并可以处理该文件,并处理响应。

The simplest way if you are running the Application Pool in Integrated mode is to tell IIS to send all requests to the "Managed Handlers". 如果以集成模式运行应用程序池,最简单的方法是告诉IIS将所有请求发送到“托管处理程序”。

In your web.config you should have a <system.webServer> element which may have a modules element - update that to: 在您的web.config中,您应该有一个<system.webServer>元素,该元素可能有一个modules元素 - 将其更新为:

<system.webServer>
  <modules runAllManagedModulesForAllRequests="true">
  [...]

With that in place you'll be able to use all the standard features of ASP.NET including authentication control on paths. 有了这些,您将能够使用ASP.NET的所有标准功能,包括路径上的身份验证控制。

Note that this will send all requests through your application, so you'll see requests for .css and .js files in there as well so if you do try locking everything down you'll need to leave those open. 请注意,这将通过您的应用程序发送所有请求,因此您将看到对.css.js文件的请求,因此如果您尝试锁定所有内容,则需要将这些请求保持打开状态。

Yes, IIS has such setting, Handler Mapping . 是的,IIS有这样的设置, Handler Mapping

The setting determines with handlers would be called for different file extensions. 使用处理程序确定的设置将针对不同的文件扩展名进行调用。 Set the ASP.NET handler to desired extensions, and the you can use ASP.NET features ( IHttpModel and other) to capture. 将ASP.NET处理程序设置为所需的扩展,您可以使用ASP.NET功能( IHttpModel和其他)来捕获。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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