Posts

Showing posts from February, 2010

The Forgotten Web.Config Inheritance Elegance

When you are running multiple Web Applications on a server you sometimes bumped into a challenge that the web.config are cumulative.  This can make life sweet for some things, for example you only need to specify the SMTP server settings once, in the root web.config.   There can be other times when you wish to have only a percentage of the parent web.config inherited into your application. The magic control element is <location> .   You may put this around any child element of <configuration> (remembering to keep it valid XML) and then include or exclude elements.   < configuration > < location path ="PublicSite" > < system.web > <!-- settings for "PublicSite" go here... --> </ system.web > </ location > < location path ="PrivateSite" > < system.web > <!-- settings for "PrivateSite" go here... -->

Using SQL Updateable Views to do live refactoring

Recently I inherited a project with a doubly ugly code base. Both the C# and the database were ugly.  To describe it simply, property information was gathered from various counties with the column names matching the terms each county used on their web site and each county given it’s own table.  A totally denormalized datamodel from purgatory.   The project is live and thus options for a refactor were reduced. The first step was to build an application that allowed everything to be mapped to standardized field names. Once that was done, the magic was to create an updatable view on each table using the new field names. Super-setting the fields ended up a UNION able set of views with the same field names. Voila, I could start doing new development or refactors against these views while not breaking the existing ugly code base as well as providing cross county queries easily   As more and more refactoring happens, I can then flip the views to tables and retire the tables from hell.

Adapting the XML mindset with SQL Server

Image
The addition of native XML support to SQL Server has been one of the smartest database moves that Microsoft has done and has moved it ahead of all competitors. There is a challenge because many database developers are Xml-illiterate or marginally literate so it often is under utilized or misused.   A common “trick” that I used to judge a Sql developer skills with XML is to ask them this question: You have a Class table with ClassId, ClassName etc A Student table with StudentId, Student Name etc A Registration table containing only ClassId and StudentId Please write a TSQL statement to return all students with the name of the classes they are in as a XmlDocument.   What I looked for is if the person asks if “Do you want two nodes (Student, Class) or three nodes (Student, Registration, Class)” – Answer I want two: Student, Class.  I don’t want to see the Role table.   If they seem confused about what I want as output (I tend to look for folks that will fill in

Using IEnumerable

This method I posted a couple of days ago is my favorite way to get data from SQL server; it returns an IEnumerable of a private class.  Programming with IEnumerable requires a different thought process then when you are dealing with arrays.   For example when you are dealing with arrays you can check to see if they are empty by calling the Length property and comparing it against zero.  Which would be very expensive if you returning all the rows from SQL server call just to see if one row existed.  However, with IEnumerable you only need one row to “prove” that some exist.  Here is my IEnumerable HasMembers() method.   1: public Boolean HasMembers 2: { 3: get 4: { 5: foreach (Member member in Members()) 6: return ( true ); 7:   8: return ( false ); 9: } 10: } Along with my Members() method that returns the IEnumerable, I include this method to quickly check f

A strategy for building a Section 508/WCAG Telerik radGrid page

Accessibility and translations can often result in a medusa head for code. On one hand you want a feature rich grid but you are constrained by Section 508.  Managing and tracking resource mnemonic across a large project becomes a nightmare (and very very boring code typing for developers which usually impacts quality control).  Another pain with a large site is consistency of presentation.   What if I claim that all you need to do is toss the code below into a page and be done with coding!   The Web Page Content: 1: <telerik:RadGrid runat= "server" ID= "AccountSummaryGrid" DataSourceID= "AccountSummaryDb" AccessKey= "X" > 2: <MasterTableView AutoGenerateColumns= "false" DataKeyNames= "AccountName" > 3: <Columns> 4: <telerik:GridBoundColumn DataField= "AccountName" UniqueName= "Grid_AccountName" >

Planning for Web Accessibility Compliance

Image
Web Accessibility compliance is often the unknown country for web developers. There are a few cases where it is required (or if specified in the contract and ignored, can change a profitable contract into a major loss leader). A constant problem is looking at the past and not the future – do you really want to deliver a product that will likely violate either the law or standards within a few months? Well, some folks would really want to do so, in order to have the work of updating the sites to conform next year .   The timeline below shows the current state of evolution: To understand the trend remember the following: Section 508 was based on the drafts of WCAG 1.0 The proposed update of Section 508 was based on drafts of WCAG 2.0 The Access Board is an ongoing government group that sets the technical details for Section 508. They have the legal authority to update the standards to most, if not all, of WCAG 2.0 Now, if you wish to deliver a STANDARDS based web

The forgotten file for .Net Web Sites and Applications: Now to throttle a website

I frequently observe that may sites and applications do not have a Global.asax file. One sweet use of such a file is the ability to keep a site appearing well behaved to users and the ability to throttle load the moment any component starts to fail due to load, network issues or whatever. First, you NEVER want a site to vomit .Net/C# error messages. Not only is it not professional, the information shown can sometime be used to hack the site. Second, if components are failing due to load or unexpected problems, you really want to tell the users to go away and come back later. The problem is knowing when to send users away. First we add a global error trap – if you forgot to do a try/catch somewhere in your code – fear not, this will handle it! 1: /// Page to send user to if any unexpected error occurs 2: private static string offlinepage = "~/NotAvailable.htm" ; 3: /// Cookie Name 4: private static string offlin

Serializing Data Transfer for Performance

Sometime when you review other’s code you see coding that causes you to ask “Why code it THAT way, instead of {2-6 alternative approaches}”. With CLR I have long stated, “What you get for performance is often NOT what you expected for performance”. I decided to look at the performance of three ways of passing data via an Array (best performer in early blog) via serialization. I exclude the actual data transfer via TCP that would occur in a Web Service/WCF – but included the LENGTH of data serialized as a data point. Assembly the data Convert to an Object or a Structure and add to an List Convert the list to an Array Serialize the array Deserialize the array to return the original array. The objects are simple: A Structure – light weight and one would expect best performance 1: public struct ViaStructure 2: { 3: public string Name; 4: public int NameLength; 5: public bool IsEmpty;