Archive, ASP.NET

Enabling Session State In IHttpHandlers

Jason / February 25, 2008

Sometimes it is handy to have the HttpSession available from your custom IHttpHandlers. By default the session state is unavailable from IHttpHandlers, and attempting to access it will result in a NullReferenceException. To make session state available simply implement the IRequireSessionState interface.

using System.Web; using System.Web.SessionState; public class SomeHandler : IHttpHandler, IRequiresSessionState { public void ProcessRequest(HttpContext context){ //do processing that requires session state. //use the context.Session to acquire the session state. } public bool IsReusable { get { return false; } } } read more

.NET, Archive, ASP.NET

ASP.NET MVC In Action

Jason / February 23, 2008

Manning has now announced the early access available of the book ASP.NET MVC In Action through their MEAP program.

The title is scheduled to be published in October of 2008, but through the early access program you can start reading the chapters as the authors write them. This particular book looks promising as it will provided a pragmatic explanation of MVC tailored towards ASP.NET developers. read more

Archive, ASP.NET

Getting Started With ASP.NET MVC

Jason / February 19, 2008

For seasoned ASP.NET developers, with the advent of true MVC support in ASP.NET, it may a little confusing of how and where to start.

For starters what is MVC, and what does it have to do with ASP.NET?

MVC is a software pattern for the UI tier, most popularly used in website development. MVC is an acronym for Model-View-Control which happens to be the three core concepts of the MVC pattern. read more

Archive, C#, NHibernate

NHibernate Formula Properties

Jason / February 19, 2008

One often overlooked feature of NHibernate is the use of formula properties. Formula properties are properties that do not map to columns in the database, but instead are mapped using raw SQL queries.

The formula is mapped in the NHibernate mapping file using the same property element that normal properties use, just replacing the column keyword for the formula keyword.

<property name="FormulaPropertyName" formula="SQL STATEMENT" /> 

The basic idea is that when NHibernate loads your object it will issue your custom SQL at the same time, allowing for complex read-only properties to offload their work to the database.

For example, assume you have an class representing an order on an e-commerce website. An order is typically composed of line items, and a common question to ask the order as a whole is “what is your subtotal?”. Without weighing the pros and cons of such a decision assume that you do not want to store the subtotal as a field on the order table.

A perfectly acceptable solution would be to have a read-only property as such:

public decimal SubTotal{ get{ decimal subTotal = 0; foreach(LineItem li in this.LineItems){ subTotal += li.ExtendedPrice; //i.e., units ordered times unit price. } return subTotal; } } read more