Deployment, Builds, and Finishing Up
<eventMappings>
<add name=”LoginSuccess” type=”System.Web.Management.WebAuthenticationSuccessAuditEvent,System.Web,Version=2
.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a” startEventCode=”0” endEventCode=”2147483647”/> </eventMappings>
The <providers> element specifies which source to write the error information to, such as Event Log or SQL Server database. Providers always have two compulsory attributes: name and type. The <provider> must use a name attribute corresponding with a name specified in <eventMappings>. Providers may have other compulsory attributes, but these will vary depending on the type of provider. The EventLogProvider only requires the name and type attributes:
<providers>
<add name=”EventLogProvider” type=”System.Web.Management.EventLogWebEventProvider,System.Web,Version=2.0.0.0, Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a” /></providers>
If you scroll down the Event Log entry you will see a whole stack of useful information about the login. This information includes the event message, the time the error occurred, the location of the error, the error message, the user’s IP address, whether or not they were authenticated, and much more.
Mailing an Administrator
Wrox United now writes to an Event Log, but this is only of use if the administrator is on hand to check the Event Log. A more proactive approach might involve e-mailing the administrator each time the monitored event takes place. Doing this requires only minimal alteration of the <healthMonitoring> element. You only need to change the rules of which provider you are indicating and the provider itself, and also add a SMTP section to the web.config file (if there isn’t an existing one). You can change the details of the <rules> element and the <providers> element and add an SMTP section very simply.
Please note that this Try It Out also requires a working SMTP server. Only if you have IIS installed with the SMTP service (done via the Add or Remove Programs section of Control Panel) will you be able to do this.
Try It Out |
Mailing the Administrator |
1.Open Web.config and alter the <rules> element so that it now reads as follows:
<add provider=”EmailProvider” name=”My Failure Audit” eventName=”Failure Audits” />
2.Go to the <providers> element and change it so that it now reads as follows:
<add name=”EmailProvider” type=”System.Web.Management.SimpleMailWebEventProvider” from=”myemail@myserver.co.uk” to=”myemail@myserver.co.uk”
subjectPrefix=”Failed Login Attempt:” buffer=”true” bufferMode=”Notification” />
Replace myemail@myserver.co.uk with your own SMTP server’s domain name. If your machine is TESTONE, replace it with myemail@testone.com.