55

I installed the elmah.mvc nuget package and kept the default configuration of that sans setting up sending an email and plugging it into a SQL database.

On my local machine when I use the Visual Studio host, I can open my app and access /elmah fine to see a report of the errors. However, when I try and access /elmah on production, I get two errors, first I get a 403 access is denied server error. Then in my email (from elmah) I get:

System.Web.HttpException: Server cannot set status after HTTP headers have been sent.

Anyone know what is going on here and how to fix? Thanks.

I tried the following so far as suggested by the answers below:

In <system.webServer>

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

And in <system.web>

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

I tried setting the path to both elmah.axd and simply ~/elmah. All still give the same error, and still works locally, but not in production.

Edit: It actually also works when I remote into the server and access it via browser on there (not using localhost, but the actual site address). So what permission am I not having? Seems like it's at the server level.

SventoryMang
  • 9,656
  • 12
  • 66
  • 103
  • You will also want to look at this post if you are in production: http://stackoverflow.com/questions/4416318/how-to-secure-elmah-axd – Shane Courtrille Jul 26 '12 at 17:13
  • I guess I should clarify that I just meant when accessed from somewhere other than via localhost, it's not necessarily our live server that other people can access. – SventoryMang Jul 26 '12 at 17:32
  • IIS 6 or 7? Any permissions explicitly set on .axd files inside IIS? – Josh Jul 26 '12 at 19:20

2 Answers2

118

You need to enable Elmah for remote access by adding the following configuration setting to the <elmah> section in your web.config file. The default setting for this value is false, which only allows localhost, hence why it is working on your local machine from within Visual Studio.

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

I always seem to forget this myself and spend a few minutes scratching my head ;)

Paige Cook
  • 21,869
  • 3
  • 52
  • 67
  • 3
    Just Googled to find this answer and was about to upvote it when I realised I already did - presumably last time I tried to configure Elmah and forgot about this! Thanks :) – Jamie Humphries Apr 27 '14 at 00:48
  • 2
    just had the same problem as Jamie Humphries... some answers are deserving of multiple upvotes – Anthony Shaw Jul 16 '14 at 17:09
  • I added the thing in system.web like DOTang said and then this and it worked ! – GabrielBB May 27 '15 at 15:41
  • trying very hard to add ` ` to my `web.config` but nothing works. Where do i add it? what pre-requisites are there? what needs to be in place before i add it? thanks. – Andrei Bazanov Jan 16 '16 at 23:05
  • Only pre-requisite is that you have the Elmah.MVC NuGet Package added to your web site. Please follow the instructions on project web site - https://github.com/alexbeletsky/elmah-mvc – Paige Cook Jan 19 '16 at 14:11
1

Make sure you HttpHandler is defined in the webServer section in your web.config file.

<system.webServer>
  <httpHandlers>
    <add name="elmah" verb="GET" path="elmah.axd"  type="Elmah.ErrorLogPageFactory, Elmah"/>
  </httpHandlers>
</system.webServer>
Iman
  • 15,560
  • 6
  • 70
  • 83
scottm
  • 26,493
  • 22
  • 102
  • 155
  • Well I am not sure if you meant to put that in system.web because system.webServer only has a tag, but I tried putting this in both places and also trying both elmah.axd and ~/elmah in the path (since it's MVC) and it still doesn't work and still has the same errors. – SventoryMang Jul 26 '12 at 17:19
  • 1
    Have you added a route for the handler? You might already have an ignore route for and *.axd requests. – scottm Jul 26 '12 at 17:58
  • How would I do that? There is no controller/action for the route. Also yes I do have `routes.IgnoreRoute("{resource}.axd/{*pathInfo}");` but the question would be then, why does it work locally on localhost, or even when browsing to the URL (not localhost) directly on the server without adding these handlers or routes? This is using Elmah.Mvc, so a lot of the custom rigging (which seems to be what you suggested based on articles I've seen) to hook it up to MVC isn't necessary...though something is still not working. – SventoryMang Jul 26 '12 at 18:31