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.

3
  • You will also want to look at this post if you are in production: stackoverflow.com/questions/4416318/how-to-secure-elmah-axd Jul 26, 2012 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. Jul 26, 2012 at 17:32
  • IIS 6 or 7? Any permissions explicitly set on .axd files inside IIS?
    – Josh
    Jul 26, 2012 at 19:20

2 Answers 2

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

5
  • 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 :) Apr 27, 2014 at 0:48
  • 2
    just had the same problem as Jamie Humphries... some answers are deserving of multiple upvotes Jul 16, 2014 at 17:09
  • I added the <httpHandlers> thing in system.web like DOTang said and then this and it worked !
    – GabrielBB
    May 27, 2015 at 15:41
  • trying very hard to add <elmah> <security allowRemoteAccess="true"/> </elmah> 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. Jan 16, 2016 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 - github.com/alexbeletsky/elmah-mvc
    – Paige Cook
    Jan 19, 2016 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>
3
  • Well I am not sure if you meant to put that in system.web because system.webServer only has a <handlers> 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. Jul 26, 2012 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, 2012 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. Jul 26, 2012 at 18:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.