Archive for February, 2008

ASP.NET 2.0 and Global.asax: What not to do

I deployed a site today that has some code in the Global.asax event handlers. I let Visual Studio 2008 add the file to my project when I created it, and it put the code directly in the file inside <script runat=”server”> tags. I went with it. So when I deployed the file, none of the events fired. Ever. The lesson is: Don’t put your code in the global.asax file. Apparently this problem is by design. There is a vague KB Article on this problem, but the solutions aren’t all that helpful, I didn’t want to pre-compile, and the first solution made no sense at all. A little searching and I found one good solution: put a class that inherits HttpApplication in the App_Code folder as described here. What I don’t understand is why Visual Studio adds the file that way if it isn’t going to work on an xcopy deployment. Microsoft seems to go out of their way to protect us from ourselves so often that I am surprised the IDE does something intentionally that won’t work.

Posted on:
Posted in ASP.NET, Visual Studio | Comments Off on ASP.NET 2.0 and Global.asax: What not to do