2013-03-24 103 views
1

我正在使用asp.net mvc应用程序。我在web.config中的以下条目处理404的404仅重定向页面而不是图像

<httpErrors errorMode="Custom" existingResponse="Replace"> 
<remove statusCode="404" subStatusCode="-1" /> 
<error statusCode="404" path="/Error/Error404" responseMode="ExecuteURL" /> 
</httpErrors> 

这工作得很好,当被请求页,它重定向到我的404视图。但是,对于丢失的图像,它也会重定向到404页面,即。图像的响应是404页面。

由于这是一个性能问题,有没有什么办法可以改变上面的内容,使得只有404个“页面”而不是像图片这样的资源会触发重定向到404页面?

+0

你的问题还不清楚。 “页面”是什么意思?你想要它处理哪些网址? – SLaks 2013-03-24 13:57:53

回答

4

您可以禁用runAllManagedModulesForAllRequests

<system.webServer> 
    <modules runAllManagedModulesForAllRequests="false" /> 
    ... 
</system.webServer> 

当然现在你会看到IIS默认404页破碎的形象,因为静态资源会被静电处理直接送达,并通过托管管道不会。

+0

感谢你 - 任何方式,我可以关闭它的图像只等等或另一种解决方法。对于我的网站中的其他功能,我需要打开此功能。 – amateur 2013-03-24 14:22:41

+1

只有在IIS中没有像* images *这样的概念。有静态和管理资源。你可以编写一个通用的处理程序或控制器来为你的图像提供服务,并拥有更多的控制权,但这是你真正需要的吗? – 2013-03-24 14:23:27

3

我知道这是一个古老的问题,但我刚刚遇到同样的问题,我能够根据我在htaccess中使用的解决方案提出解决方案。

下面的解决方案基本上检查文件是否有图像扩展名,它不是一个文件,也不是一个目录。之后,它提供了一个我用来识别丢失图像的图像文件。

<rule name="404 Images" stopProcessing="true"> 
    <match url=".*" ignoreCase="true" /> 
    <conditions> 
     <add input="{URL}" pattern="^.+\.(jpg|jpeg|png|gif|ico)$" ignoreCase="true" negate="false" /> 
     <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="true" negate="true" /> 
     <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="true" negate="true" /> 
    </conditions> 
    <action type="Rewrite" url="/design/images/404.png" /> 
</rule> 
相关问题