【问题标题】:.net 4 MVC 2 Elmah is logging background-image.net 4 MVC 2 Elmah 正在记录背景图像
【发布时间】:2011-09-22 01:41:00
【问题描述】:

我在我的 MVC 2 项目中使用 Elmah 并且一切正常 - 除了 Elmah 将我的背景图像记录为未实现的控制器(请参阅http://imageshack.us/photo/my-images/834/unbenannt1ak.png/)。

这张图片是通过我的css设置的

body
{
background: #d9dbea url('scanlines.png');
}

为什么会这样?

【问题讨论】:

  • 也许您可以发布您的路由配置。
  • 你的意思是在全球asax?这几乎是默认值:'public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("elmah.axd"); routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute("Default", // Routenname "{controller}/{action}/{id}", new { controller = "Home", action = "Index", id = UrlParameter.Optional } ); }'

标签: asp.net-mvc asp.net-mvc-2 elmah


【解决方案1】:

好吧,我终于拿到了这个……

这似乎是一个“常见”错误,Elmah 记录了favicon.ico,如果它不在您的根目录中。为了克服这个问题,您可以创建一个过滤器,如下所示。我只需要添加另一个过滤规则,这样 Elmah 就不会像我之前所说的那样记录scanlines.png(或只是另一个图像)。过滤规则是

<errorFilter>
<test>
  <and>
    <equal binding="HttpStatusCode" value="404" type="Int32" />
    <or>
      <regex binding="Context.Request.ServerVariables['URL']"
             pattern="/favicon\.ico(\z|\?)" />
      <regex binding="Context.Request.ServerVariables['URL']"
             pattern="/scanlines\.png(\z|\?)" />
      <regex binding="Context.Request.ServerVariables['URL']"
             pattern="/yourimage\.jpg(\z|\?)" />
    </or>
  </and>
</test>
</errorFilter>

有了这个,你可以阻止 Elmah 记录的不需要的图像。希望这可能对某人有所帮助 ;-)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-04-04
    • 2011-06-08
    • 2014-05-07
    • 1970-01-01
    • 1970-01-01
    • 2020-11-24
    • 1970-01-01
    • 2014-02-03
    相关资源
    最近更新 更多