Dela via


Resolving issues with Code Behind / Code File conversions in IIS 2003 - 2008

I recently encountered a strange issue while migrating an older Web site that was developed in Visual Studio 2003 to 2008.  The code behind (codebehind) attribute in the asp/x page was changed to code file (codefile) in ~ 2005 and in that edition of Visual Studio threw a warning.  In 2008, the pages simply don't render and Visual Studio silently ignores them.   This is rather frustrating as it can take a little while longer to realize what is going on.  I have a feeling that the server should just error, but as this is really just a matter of "ignoring" invalid attributes in an @ASP tag, I can understand the argument for ignoring the tags and just assuming the pages don't have associated "code behind" pages.

At any rate, the magic changes I made were pretty much like the following:

from:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Comments.aspx.cs" Inherits="DocReports._Comments" %>

to:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Comments.aspx.cs" Inherits="DocReports._Comments" %>

And all of a sudden my code behind pages were working again and getting picked up by the site pre-compiler.  I also had to move the libraries into an APP_CODE folder to get them recognized by the code behind pages.  I think to further complicate my situation, IIS was using a precompiled binary (from the old site) that made the pages automagically work (they were looking into the binary for resolutions) but never recompile.  Anyways, I'm relieved my site is back to functioning, just a little frustrated that I had to jump through so many hoops to figure out what was wrong.

Hopefullly not too many people hit this issue, but hopefully if they do, a search engine has picked up these notes.

Comments