Category Archives: ASP.NET

Following the suggestion from Scott and Jeff, I decide to have ELMAH implemented in my current ASP.NET application as well. The whole progress is really straightforward and painless. Most of the work is to modify the application’s web.config file.

    • Download the latest version of bin, currently 1.0 version, from project’s web site, hosted on Google code.
    • Based on the version of your ASP.NET application, reference the corresponding Elmah.dll from the subfolder. You might need to reference SQLite.dll if you need to use SQLLite for the log storage.
    • Modify the Web.config based on the sample Web.config file coming with the sample. You can check it from here as well.

 

That is it! Then you can find the unhandled exception by access http://yourwebsite/elmah.axd. You will see the error page is something like

elmah.axd-with-error

From what I see so far, ELMAH is

  • Easy to implement and set it up
  • Flexible to offer multiple log storage providers, including SQL Server, SQLLite, Oracle, XML, and In-memory.
  • Readable, the log is formatted in a HTML table, which can be also export to CVS file and be queried by Microsoft’s Log Parser tool.
  • Reliable, it provides multiple notification channels, including Email, RSS and even Tweet.

Just as Jeff Atwood said in his blog above, the main purpose of setting up ELMAH in our application is to find out the accurate, valuable and real time “feedback” of the applications we built automatically.

Happy coding, till next time!

MVC is a very common pattern used in OO design to break the responsibilities into different components, Model, View and Controller. It is often used in the UI layer. We can easily find in its various implementations Java or Smalltalk. But this practice is not very common for .NET developers. Maybe it is not what Microsoft recommends. Microsoft has its own concept call page controller. Basically it treats the ASP.NET code behind as the controller itself. Code in codebehind can call service layer to get Model, then display onto the aspx page. This module is working fine under Microsoft’s IDE tool, Visual studio .NET. But the problem is page controller is bound with its view. It is not easy to separate. It is impossible for me to reuse the logic in the controller into Win form. For instance, the controller has some navigation logic which can be applied onto both win form and web form.

Currently my own approach is to apply MVP pattern in very web control in the page (I prefer to use web controls on the page) to delegate the business logic into service layer, and rely on a application level navigation controller to manage the page flow. The navigation controller is some type of sate machine implementation. You can find a excellent article by Michele Leroux Bustamante in MSDN. Andy Hunt has an article regarding this topic as well. For those developers who like to implement a MVC framework, there are some of the options:

1. Microsoft UIP. UIP came with Microsoft Application Building Block 2. But it seemed not as popular as its counterparts, like data building block or log building block. Still probably because of most of the developers don’t realize how important it is to separate the responsibilities and promote testability for the whole application. Again this core implementation is inherited from Microsoft page controller concept. You have to inherit its base page (default controller). Some resources which I recommend to read for UIP

CodeProject – User Interface Process Application Block (UIPAB)

CodeProject – UIPAB Part 2: MVC, UIPAB Essentials and Demo

UIP with PetShopDNG 2.0 (French)
2. MonoRail in Castle Project. MonoRail is inspired by Ruby on Rails. It implements a truly MVC pattern. The Rails engine sit behind as a Front controller to direct the request to the right page. Combined with Active Record, which is excellent implementation upon NHibernate, MonoRail can provide a very fast and maintainable development environment. Although Web Form is one of its supported view, it is more likely use Nvelocity. So its design is not as easy as in Visual Studio, also it lacks developer community support. Maybe it will change as Ruby on Rail gains such popularity recently.

3. Castle MVC Framework. It is very interesting project hosted in Castle. But currently it still in sandbox for reviewing. It is inspired by Microsoft UIP and MVC implementation from MonoRail. Actually the lastest version of Nshop2, sample application of iBatis .NET, is using this MVC framework. Similar with other MVC framework, it uses XML to define the mapping between the views and commands. The other advantage form Castle MVC is that it can be treated as facility to be plugin into Castle IOC container.

4. Maverick.NET. It was dead for a while. But some developers just pick it up recently. It releases its 1.12 version this January. Maverick .Net uses XML to configure sitemap. Its controller supports Pages and Controls. It does not have complete documents. But it does not too hard to figure out how to use it.

Does anybody can add more? :=)

In my recent projects, I am extensively using Model-View-Presenter (MVP) pattern in the presentation tiers. It easily seperates the responsiblities, and makes my testing easily. Jeremy Miller has two great blogs recently talking about MVP, Unit testing and Regression testing in ASP.NET. You can check it from here and here. He also told about using FitNesse for regression testing, which makes me very interested. I am going to put it on my to-do list.

As far as MVC pattern, I still don’t find a better solution yet. Althought Microsoft claim its ASP.NET codebehind is a controller, I just don’t think so. Castle has a implementation of MVC, but still in its sanbox. The NPetShop2, another implementation of PetShop, from iBatis is heavily using this implemenation. But still, it is in the sanbox. If you have interest, you can access their source code to take a look at. Microsoft has its own UIP (User Interface Process) building block. But I need to customize the source code to make it useful to me, since I already has a BasePage for my ASP.NET application to store common functions. I am keeping looking at…