Tuesday, March 30, 2010

Web.config files and legacy products

I've been working with a CMS product called Ektron CMS400.net for the last couple months. Well that's a lie. I haven't been using it the entire time. A lot of the time has been spent just getting the product up and running in our environment. We will save all that for maybe another post.

This post is about upgrading legacy product web.config files to work with newer technologies. This particular instance revolves around the ability to use "var" and extension methods available in .Net 3.5 in the actual inline code of an aspx page.

The scenario is that I wanted to create a wrapper extension method to string that I would pass in a string tag name and it would wrap the string with the appropriate tag based on that name. I did this and everything works when in cs files. That changed when it came to consuming the same extension method inline.

The following piece of code threw a "'System.string' does not contain a definition for 'WrapWithTag'" error:


I then did some quick Googling to find out what I could do to fix this, or even if I could. AHA! I found it. It was due to the missing lines in the web.config file. Below you will see the difference between the standard 2.0 Web.config file to a 3.5 version. (The Web.config file I was working with was a monstrosity in comparison)

.Net 2.0 Standard Web.config file:


.Net 3.5 Standard Web.config file:


The actual piece that I needed in my Web.config file was:


This piece ensured that the ASP.Net compiler would run .Net 3.5 instead of 2.0.

No comments:

Post a Comment