ASP.NET MVC - Elmah 不工作并返回 elmah.axd 的 404 页面

发布于 2024-08-18 15:14:09 字数 2732 浏览 8 评论 0原文

我正在尝试将 elmah 用于我的 MVC 应用程序,并且已按照 wiki 上的步骤操作: http://code.google.com/p/elmah/wiki/MVC ,但即使如此,当尝试访问 myapp/elmah.axd 页面时:

404 - 未找到文件或目录。

有人可以帮我吗?

OBS:我的 IIS 版本是 7.5


如果有帮助,我将发布 web.config 的相关部分:

<sectionGroup name="elmah">
  <section name="security" requirePermission="false" type="Elmah.SecuritySectionHandler, Elmah" />
  <section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah" />
  <section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler, Elmah" />
  <section name="errorFilter" requirePermission="false" type="Elmah.ErrorFilterSectionHandler, Elmah" />
</sectionGroup>
...
</connectionStrings>
<elmah>
  <errorLog type="Elmah.XmlFileErrorLog, Elmah" logPath="~/App_Data" />
</elmah>
<system.web>
...
<httpHandlers>
  <remove verb="*" path="*.asmx" />
  <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
  <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
  <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false" />
  <add verb="*" path="*.mvc" validate="false" type="System.Web.Mvc.MvcHttpHandler, System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
  <add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
</httpHandlers>
<httpModules>
  <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
  <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
  <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
  <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />            
  <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" />
</httpModules>

以及我的 Global.asax.cs

public static void RegisterRoutes(RouteCollection routes)
{   
  routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
...

I'm trying to use elmah for my MVC application and I've followed the steps on the wiki: http://code.google.com/p/elmah/wiki/MVC , but even so when trying to access myapp/elmah.axd the page:

404 - File or directory not found.

Anyone could help me please?

OBS: My IIS Version is 7.5


If helps I'm posting the pertinent sections of my web.config:

<sectionGroup name="elmah">
  <section name="security" requirePermission="false" type="Elmah.SecuritySectionHandler, Elmah" />
  <section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah" />
  <section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler, Elmah" />
  <section name="errorFilter" requirePermission="false" type="Elmah.ErrorFilterSectionHandler, Elmah" />
</sectionGroup>
...
</connectionStrings>
<elmah>
  <errorLog type="Elmah.XmlFileErrorLog, Elmah" logPath="~/App_Data" />
</elmah>
<system.web>
...
<httpHandlers>
  <remove verb="*" path="*.asmx" />
  <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
  <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
  <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false" />
  <add verb="*" path="*.mvc" validate="false" type="System.Web.Mvc.MvcHttpHandler, System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
  <add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
</httpHandlers>
<httpModules>
  <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
  <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
  <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
  <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />            
  <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" />
</httpModules>

And on my Global.asax.cs

public static void RegisterRoutes(RouteCollection routes)
{   
  routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

送你一个梦 2024-08-25 15:14:09

对于 IIS 7+,您还需要填充 system.webServer 配置部分。 请参阅这个问题

You need to populate the system.webServer config section also, for IIS 7+. See this question.

洋洋洒洒 2024-08-25 15:14:09

这是在 MVC 中使用 ELMAH 的好方法这里 不使用 axd,而是使用控制器和自定义 ElmahActionResult

Here's a nice way of using ELMAH in MVC here that doesn't use the axd but a controller and a custom ElmahActionResult.

花落人断肠 2024-08-25 15:14:09

尝试将其添加到您的 web.config 文件中

<system.webServer>

    <handlers>
        <remove name="ErrorLog" />
        <remove name="ErrorMail" />
        <remove name="ErrorFilter" />
        <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
        <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />            
        <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" />     
    </handlers>       
</system.webServer>

Try adding this to your web.config file in the

<system.webServer>

    <handlers>
        <remove name="ErrorLog" />
        <remove name="ErrorMail" />
        <remove name="ErrorFilter" />
        <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
        <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />            
        <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" />     
    </handlers>       
</system.webServer>
云雾 2024-08-25 15:14:09

为了帮助其他人体验 @zanona 在 2010 年遇到的问题(请参阅上面对 @hunter 回复的评论),以下更改今天为我修复了完全相同的“HTTP 错误 500.19 - 内部服务器错误”。请注意,@hunter 的回复中配置标签的位置导致了 @zanona 的错误。 @hunter 提到的那些标签属于模块标题,而不是处理程序标题!

<modules>
  <remove name="ErrorLog" />
  <remove name="ErrorMail" />
  <remove name="ErrorFilter" />
  <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
  <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />            
  <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" /> 
 </modules>       

上述修复为我消除了 @zanona 首次报告的相同“配置错误 - 缺少所需属性‘路径’”问题。该错误是由于处理程序组中的标签预期的结构方式造成的,而他重新排列的标签显然没有路径属性(因为它们不属于那里,而是属于模块标签! )。现在,处理程序部分中的标记应如下所示:

<handlers>

  <add name="elmah" verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />

</handlers>

注意到那里存在路径属性了吗?啊!

感谢@hunter 和@zanona,因为他们确实让我走上了解决问题所需的道路。

(注:我尝试编辑上面 @hunter 的原始帖子以进行更正,但同行评审速度很慢,我想我会在这里保留此回复,以帮助同时面临相同挑战的任何人。当该编辑是接受,我们可以删除这篇文章。)

To help others experiencing what @zanona ran up against way back in 2010 (see comments to @hunter's reply above), the following change fixed the very same "HTTP Error 500.19 - Internal Server Error" for me today. Notice the placement of the configuration tags in @hunter's reply is what caused @zanona's error. Those tags @hunter mentioned belong under the modules heading, not the handlers one!

<modules>
  <remove name="ErrorLog" />
  <remove name="ErrorMail" />
  <remove name="ErrorFilter" />
  <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
  <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />            
  <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" /> 
 </modules>       

The above fix eliminated for me the very same "Config Error - Missing required attribute 'path'" issue that @zanona first reported. That error came as a result of the way tags in the handlers group are expected to be structured, and his rearranged tags caused obviously didn't have the path attribute (because they didn't belong there, but rather belong under the modules tag!). Now here's what tags in the handlers section should look like:

<handlers>

  <add name="elmah" verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />

</handlers>

Notice the path attribute is present there? Ah!

Thanks to @hunter and @zanona because they did set me on the path I needed to solve my issue.

(NOTE: I've tried to edit the original post from @hunter above to make the corrections but peer review is slow and I thought I'd keep this reply here to help anyone facing the same challenge in the meanwhile. When that edit is accepted, we could delete this post.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文