Elmah.MVC returns 403 in Local Environment

93 Views Asked by At

I have installed Elmah.MVC into a project I'm working on and tried to browse to /elmah but am constantly greeted by this error:

You are attempting to access ELMAH from a remote machine whereas itis currently configured not to allow remote access. You can enableremote access by adding the following sections to this web site'sconfiguration file:

<configuration>
         <configSections>
             …
             <sectionGroup name="elmah">
                 <section name="security" type="Elmah.SecuritySectionHandler, Elmah" />
             </sectionGroup>
             …
         </configSections>
         <elmah>
            <security allowRemoteAccess="yes" />
         </elmah>
         …
     </configuration>

The thing is, I'm running the application in Debug mode on my Local Machine and not remotely.

My Web Config looks as follows:

<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>
  ......
  <appSettings>
    <add key="elmah.mvc.disableHandler" value="false" />
    <add key="elmah.mvc.disableHandleErrorFilter" value="false" />
    <add key="elmah.mvc.requiresAuthentication" value="false" />
    <add key="elmah.mvc.IgnoreDefaultRoute" value="false" />
    <add key="elmah.mvc.allowedRoles" value="*" />
    <add key="elmah.mvc.allowedUsers" value="*" />
    <add key="elmah.mvc.route" value="elmah" />
    <add key="elmah.mvc.UserAuthCaseSensitive" value="true" />
  </appSettings>
  ......
  <httpModules>
    <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
    <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
    <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" />
  </httpModules>
  ......
  <system.webServer>
    <modules>
      <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" preCondition="managedHandler" />
      <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" preCondition="managedHandler" />
      <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" preCondition="managedHandler" />
    </modules>
  </system.webServer>
  ......
  <elmah>
    <errorLog type="Elmah.SqlErrorLog, Elmah" connectionStringName="Elmah" />
    <security allowRemoteAccess="false" />
  </elmah>
</configuration>

I've used Elmah before in other projects without encountering this issue. I'm using Visual Studio 2017, MVC5 and .NET Framework 4.5.2

Anyone have any ideas?

1

There are 1 best solutions below

1
On

I HAD the same issue. I was definitively accessing locally, I tried "localhost" and "127.0.0.1". But I could make it work with another smaller MVC project, at least remotely.

Comparing both, I noticed differences in the version of elmah.corelibrary, and I believe now that the latest version, 1.2.2 causes the issue.

So, I replaced 2 dll and have now

  • Elmah.dll v1.2 (v1.2.13605.2128) (instead of 1.2.2 or 1.2.14706.0?)
  • Elmah.Mvc.dll v2.1.2

and updated package.config :

<package id="elmah.corelibrary" version="1.2" targetFramework="net461" />
<package id="Elmah.Mvc" version="2.1.2" targetFramework="net461" />

In the Root web.config, I have the following lines related to elmah

in the configSections section :

<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>

in the appSettings section :

<add key="elmah.mvc.disableHandler" value="false" />
  <add key="elmah.mvc.disableHandleErrorFilter" value="false" />
  <add key="elmah.mvc.requiresAuthentication" value="false" />
  <add key="elmah.mvc.IgnoreDefaultRoute" value="false" />
  <add key="elmah.mvc.allowedRoles" value="*" />
  <add key="elmah.mvc.allowedUsers" value="*" />
  <add key="elmah.mvc.route" value="elmah" />
  <add key="elmah.mvc.UserAuthCaseSensitive" value="true" />

in the system.web section :

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

in the system.webserver section :

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

and under configuration

<elmah>
   <security allowRemoteAccess="true" />
</elmah>

I struggled a lot to make it all work. This last attribute can of course be set to false (and it still works locally) I hope it works for you!