简体   繁体   English

ASP.NET(WebForms或MVC)应用程序中的哪个代码组件提供图像等网站资源?

[英]Which code component in an ASP.NET (WebForms or MVC) application serves website resources such as images?

When you have an image tag in your application like so: 当您的应用程序中有图像标记时,如下所示:

<img src = @Url.Content("~/foo/bar.jpg") />

or like so: 或者像这样:

<asp:image src = "~/foo/bar.jpg" />

or like so: 或者像这样:

<input type = "image" ...>

and if this happens to be an ASP.NET application (Web Forms or MVC is irrelevant to the question, I assume, as the code serving images must be the same), which specific component serves requests for images? 如果这恰好是一个ASP.NET应用程序(Web窗体或MVC与问题无关,我认为,因为服务图像的代码必须相同),哪个特定组件服务于图像请求?

Is it the Web server (IIS or Visual Studio's internal web server) or is it an ASP.NET HttpHandler that Microsoft wrote. 它是Web服务器(IIS或Visual Studio的内部Web服务器)还是Microsoft编写的ASP.NET HttpHandler。

I remember there used to be a handler for serving resource files in ASP.NET 2.0. 我记得曾经有一个处理器用于在ASP.NET 2.0中提供资源文件。 Is that the one that serves images, too? 这也是提供图像的那个吗? What's it called? 它叫什么?

Why am I asking this question / What I am trying to do 我为什么要问这个问题/我想做什么

I have an ASP.NET MVC application and I want to write my own custom HttpHandler or a Controller to serve static assets like images so that they get cached. 我有一个ASP.NET MVC应用程序,我想编写自己的自定义HttpHandler或Controller来提供静态资产,如图像,以便它们被缓存。

What I am planning to do it something almost exactly similar to http://blog.hompus.nl/2011/03/11/make-your-browser-cache-the-output-of-an-httphandler/ and http://archive.msdn.microsoft.com/ResourceCache 我打算做什么几乎完全类似于http://blog.hompus.nl/2011/03/11/make-your-browser-cache-the-output-of-an-httphandler/http:/ /archive.msdn.microsoft.com/ResourceCache

I want to make sure that if there's one already written by Microsoft, I might need to take some precautions while sending back Http headers in the response just so that the headers Microsoft's in-built httpHandler sets are not in contradition to the ones I set. 我想确保如果有一个已经由Microsoft编写,我可能需要采取一些预防措施,同时在响应中发回Http标头,以便Microsoft的内置httpHandler集合的标题与我设置的标题不相符。

By default, all requests for ASPX pages (including static resources therein, like images) are served by the default HttpHandler , which is an instance of the PageHandlerFactory class : 默认情况下,所有对ASPX页面的请求(包括其中的静态资源,如图像)都由默认的HttpHandler ,它是PageHandlerFactory类的一个实例:

Instances are created dynamically to handle requests for ASP.NET files. 动态创建实例以处理对ASP.NET文件的请求。 The PageHandlerFactory class is the default handler factory implementation for ASP.NET pages. PageHandlerFactory类是ASP.NET页面的默认处理程序工厂实现。

As you can see from the MSDN article on HttpHandlers and HttpModules , the primary "built in" handlers are those for 正如您在MSDN上有关HttpHandlers和HttpModules的文章中所看到的那样 ,主要的“内置”处理程序是

  • standard ASP.NET files (.aspx), 标准ASP.NET文件(.aspx),
  • web services (.asmx), 网络服务(.asmx),
  • generic, non-UI handlers (.ashx), and 通用的,非UI处理程序(.ashx)和
  • one for handling the trace (trace.axd). 一个用于处理跟踪(trace.axd)。

There is not one that is specifically handling image requests. 没有一个专门处理图像请求。 So you should be good to go =) 所以你应该好好去=)

Okay, it appears to me that ASP.NET doesn't care much for any static resources and therefore, it doesn't register an ISAPI filter with IIS for any of those resources. 好吧,在我看来,ASP.NET并不关心任何静态资源,因此,它不会为任何这些资源注册带有IIS的ISAPI过滤器。

That means, as a developer who wants to write a specific handler for static resources, you're pretty much free to do whatever you want. 这意味着,作为一个想要为静态资源编写特定处理程序的开发人员,您可以随心所欲地做任何事情。

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

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