Configuring the Health Monitoring System
I had a few problems with getting the Health Monitoring System at the end of Chapter 2 (pgs. 109-110) to work, and the book is not very clear about that section. When I searched the forum, it seems several other people had problems with it too, but I didn't really find a comprehensive solution.
So I thought I'd just share what I did to get it to work, in hopes it will make things easier for someone else.
(And if there are any errors, then by all means, feel free to point them out.)
First, create a new project (File > New Project);
Project type: Visual C#;
Template: Class Library;
Name: TBHCustomEvents (or whatever your replacement name is);
Location: place it within the main project's folder;
Solution: ADD TO SOLUTION
Rename the class that was automatically created in TBHCustomEvents to "CustomEvents.cs" (or whatever you want to call it).
I then copied the code for CustomEvents.cs from the solution code and pasted it into mine. Remember to change the namespace from MB.TheBeerHouse if you're using something else.
Note that, as you'll see below, you may want to try adding the references (my next step) BEFORE you copy-paste this code. If you copy-paste it now (as I did), the code does not recognize most of the namespaces called at top of the file (ie "using System.Web.UI;" etc.).
I then added the references (right-click "References" folder under TBHCustomEvents > "Add Reference"). From the .NET list, add: System, System.Data, System.Web, System.XML.
I later found that even with these references added, they were still not being recognized at the top of the CustomEvents.cs file. As someone else pointed out, there seems to be some delay in some items being recognized. Cutting those first 10 lines from the file then pasting them back in, however, fixed it.
Click on the TBHCustomEvents project file. In the properties window, click on the "Property Pages" button.
Adjust the Assembly Namespace to "MB.TheBeerHouse.CustomEvents" (or whatever it would be for yours),
and Default Namespace to "MB.TheBeerHouse" (or whatever you're using).
Go up to the main (TheBeerHouse) project, right-click > Add Reference. Under "Projects" select the TBHCustomEvents project to make sure it's referenced.
Now you're almost done.
Copy the <healthMonitoring> section of the code (as per pg 110) from the source code into your web.config file.
Everything should now work.
I will also add this note: When I tried running the project along the way trying to fix some problems, it told me that I had problems with the web.config file. Specifically, it seemed to have a problem with the schema defined in the <configuration> tag.
You can ignore those messages. It turned out that the problem was not with the schema or even the web.config file at all. The underlying problems were all with getting the TBHCustomEvents sub-project setup correctly.
So, that's what I did, and it worked for me.
Hope that helps someone!
|