How to securely configure ELMAH with email alerts in IIS7

by Luke 3. July 2010 05:42

Over the prior two weeks we have had a number of server upgrade projects. Most have been moving from server 2003 to server 2008 R2. During the process I followed the basic installation instructions which involve modifying the web.config file manually. I couldn't get the same instructions to work for me when trying to integrate ELMAH into the new Server 2008 R2 environment. That is when I remembered that IIS7 wants to "help" us more by controlling the web.config settings via the IIS7 MMC Snap-in. Here is what I did to successfully get ELMAH working on Server 2008 R2.

1. Download the latest version of ELMAH from: http://code.google.com/p/elmah/downloads/list

2. Copy the Elmah.dll into the web application's /bin directory

Note: Make sure you copy the appropriate assembly for your server's CPU architecture (x86 x64)

3. Open up the IIS7 MMC Console

4. Select the site you want to add ELMAH to from the Tree View on the left

5. In the Features View:

a. Choose the Modules icon in the Features View

IIS7 Modules

6. On the right, under Actions, choose "Add Managed Module…"

IIS7 Actions

7. In the Add Managed Module window:

a. Type into the Name textbox: ErrorLog

b. Choose from the Type drop down list: Elmah.ErrorLogModule

Add Managed Module

8. For a second time choose "Add Managed Module…" from the right column

9. In the Add Managed Module window:

a. Type into the Name textbox: ErrorMail

b. Choose from the Type drop down list: Elmah.ErrorMailModule

Add Managed Module

10. Note: you should now have two new modules listed under Modules in the Features View

clip_image010[7]

11. Click on the Website you are editing in the treeview on the left

12. Choose the Handler Mappings menu from the Features View

IIS7 Modules

13. Under the Actions menu:

a. Click the Add Managed Handler… menu option

Actions Menu

14. In the Add Managed Handler window:

a. Type into the Request Path textbox: /admin/elmah.axd

b. Type into the Type drop down list: Elmah.ErrorLogPageFactory

Note: the Elmah.ErrorLogPageFactory must be typed, it is not available via the drop down list

c. Type into the Name field: Elmah

Add Managed Handler

15. Click the Back back button to return to the Features View

16. From the Features View

a. Double-click the Authentication icon

clip_image020[7]

17. In the Authentication window:

a. Highlight Windows Authentication

b. Click the Enable link from the Actions menu

Authentication

Note: this might require an IISReset (I had a "HTTP 503 Service Unavailable" error on my Production server but not on my Development server, an IISRESET fixed my issue)

18. Browse to the web.config file and open it in Notepad

19. Find the </configSections> XML node and insert an empty line above it to add the following Section Group

<sectionGroup name="elmah">

      <section name="security" requirePermission="false" type="Elmah.SecuritySectionHandler, Elmah" />

      <section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler, Elmah" />
</sectionGroup>

20. Following the </configSections> XML node insert the <errorMail> configuration node:

<elmah>
    <security allowRemoteAccess="yes" />
    <errorMail
      from="webmaster@domain.com"
      to="SendTo@domain.com"
      subject="Message Subject"
      async="true"
      smtpPort="25"
      smtpServer="emailServerFQDN_OrIP" />

</elmah>

21. Customize the <errorMail> node properties to match your Organization's needs

22. Finally, go all the way to the bottom and insert the following before the last </configuration> XML node

<location path="admin">

    <system.web>

      <authorization>

        <deny users="?" />

      </authorization>

    </system.web>

</location>

Note: this section secures the /admin/ URL so only authorized users can view the /admin/elmah.axd page

Now, time to test the results.

23. Navigate to http://yoursite.com/admin/elmah.axd

24. The page will prompt you for credentials

25. Login with your user account

26. Verify the ELMAH default error page will display

27. Fire off a test exception by adding /test after your current URL (example: http://yourseite.com/admin/elmah.axd/test)

28. A test exception page will appear and might look similar to this

IIS7 Error

29. Navigate back to the ELMAH default error page: http://yoursite.com/admin/elmah.axd

30. The exception will be listed in the exceptions table as a test, and if you configured the email section properly you should receive an email including the exception details

ELMAH Error Page

Tags: ,

ELMAH | IIS7

Comments

11/21/2011 7:16:55 AM #

Nice first part!

There's some of the stuff I don't agree with, but I'm totally biased (being an Umbraco fan boy and everything) :-P
I'll comment on this once all the parts are posted.

One thing though: It seems like Sitecore is trying hard to be/include more that one thing: Being a CMS, Marketing Platform and Analytics package. Umbraco will never do this (according to the founder), but only do one thing (good): Being a CMS and a content framework.

So with these two totally different approaches, one will always have more stuff/features than the other. And in my experience, that's not necessarily a good thing.

But keep up the good work! Looking very much forward to the next parts, hoping they are equally well written

Chara Herkel United States |

11/22/2011 6:12:17 PM #

Howdy I am so happy I found your site, I really found you by error, while I was searching on Google for something else, Anyways I am here now and would just like to say many thanks for a marvelous post and a all round entertaining blog (I also love the theme/design), I don’t have time to browse it all at the minute but I have saved it and also added in your RSS feeds, so when I have time I will be back to read a great deal more, Please do keep up the great job.

best lesbian dating site United States |

11/23/2011 5:01:52 PM #

Hi there can I reference some of the material here in this site if I provide a link back to your site?

Albertina Glorius United States |

11/23/2011 6:09:24 PM #

the old version seemed simpler

Apanie Cairns United States |

Comments are closed

About Luke

C# .NET developer who really likes kettle style potato chips. Current favorite is Cape Code potato chips with a Henry Weinhards root beer on the side, mmmm delicious

 
 
The views and opinions on this blog site are my own and are not that of my employer.