Elmah不能使用asp.net网站
我试图用我的asp.net网站使用elmah,但每当我尝试去http:// localhost:port / elmah.axd我得到资源找不到exception。 我的web.config如下。
<?xml version="1.0"?> <configuration> <configSections> <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> </configSections> <elmah> <security allowRemoteAccess="0" /> <errorLog type="Elmah.SqlErrorLog, Elmah" connectionStringName="elmah-sql" /> <errorMail from="my@account" to="myself" subject="ERROR From Elmah:" async="true" smtpPort="587" smtpServer="smtp.gmail.com" userName="my@account" password="mypassword" /> </elmah> <connectionStrings> <add name="elmah-sql" connectionString="data source=(sqlserver); database=elmahdb; integrated security=false;User ID=user;Password=password"/> </connectionStrings> <system.web> <compilation debug="true"> <assemblies> <add assembly="Elmah, Version=1.0.10617.0, Culture=neutral, PublicKeyToken=null"/> </assemblies> </compilation> <authentication mode="Windows"/> <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"/> </httpHandlers> <httpModules> <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> </httpModules> </system.web> <system.webServer> <validation validateIntegratedModeConfiguration="false"/> <modules runAllManagedModulesForAllRequests="true"> <remove name="ScriptModule"/> <add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah"/> <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah"/> <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah"/> </modules> <handlers> <remove name="WebServiceHandlerFactory-Integrated"/> <remove name="ScriptHandlerFactory"/> <remove name="ScriptHandlerFactoryAppServices"/> <remove name="ScriptResource"/> <add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> <add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> <add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> <add name="Elmah" verb="POST,GET,HEAD" path="elmah.axd" preCondition="integratedMode" type="Elmah.ErrorLogPageFactory, Elmah"/> </handlers> </system.webServer> </configuration>
编辑:Elmah =(错误logging模块和处理程序)
http://code.google.com/p/elmah/
尝试在<system.web>
部分的“httphandlers”和“httpmodules”部分注册Modules和Handlers:
<httpHandlers> ...... <add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah"/> ..... </httpHandlers> <httpModules> ....... <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah"/> <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah"/> <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah"/> ....... </httpModules>
我只是有一个与Elmah不在IIS7部署工作类似的问题。 我发现我需要在system.web
和system.webServer
注册Elmah模块和处理程序:
<system.web> ... <httpHandlers> ... <add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" /> ... </httpHandlers> <httpModules> ... <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah"/> <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" /> <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" /> ... </httpModules> ... </system.web> <system.webServer> ... <modules runAllManagedModulesForAllRequests="true"> ... <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah"/> <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" /> <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" /> ... </modules> <handlers> ... <add name="Elmah" verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" /> ... </handlers> <system.webServer>
你可能也需要这个
<elmah> <security allowRemoteAccess="1" /> </elmah>
当你拿到时
403 – 禁止:访问被拒绝。 您无权使用您提供的凭据查看此目录或页面。
我使用NuGet(VS 2013,IIS 8.0)进行安装时缺less此行:
<system.webServer> <handlers> <add name="Elmah" verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" /> </handlers> </system.webServer>
添加它解决了404错误的问题。
今天解决它的一个方法是使用nuget。
Visual Studio:menu-> tools-> library package manager-> package manager console
install-package elmah
HTH
nuget包不会将以下重要行添加到web.config中导致403错误。
<configuration> <elmah> <security allowRemoteAccess="1" /> <errorLog type="Elmah.XmlFileErrorLog, Elmah" logPath="~/app_data/elmah" /> </elmah> </configuration>
你也可能想限制对错误日志的访问
<add name="Elmah" verb="POST,GET,HEAD" path="/admin/elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode" />
如果您正在使用区域,请确保您已经更新了其中一个应用程序密钥
默认
<add key="elmah.mvc.route" value="elmah" />
如果您是Admin的区域
<add key="elmah.mvc.route" value="admin/elmah" />