ASP to ASP.Net Migration: Fixing Includes

24. January 2011 08:43 by Mrojas in General  //  Tags: , , ,   //   Comments (0)

During a migration from ASP to ASP.NET one of the biggest hurdles is finding a way to deal with the include files.

ASP was a interpreted environment whether ASP.NET is compiled and this difference is very important because you need to find ways more natural in .NET to do some things you used to do in ASP.

For example in ASP you used to have a set of common functionality that was included in your files. What will you do with that?

For ASP ASP.NET in VB.NET is a lot easier. One of the things you can do is move all those common subs and functions to a Module.

Now if what you have is a ASP.NET Web Site, then just your new modules to the App_Code folder and voila your pages are now able to see that code.

For a ASP.NET Web Application is just a little differente. What you have to do is move your common variables, constants, subs and functions to a Module, but that is not enough to make that code reachable from your mark up, so you have two alternatives:

1. Add an %@import Namespace=”QualfiedNamespaces.Module1”  statement for each of your modules.

2. Modify your web.config file and add under system.web something like:

<system.web>
              <pages>
                     <namespaces>
                           <add namespace="WebApplication1.Module1"/>
                     </namespaces>
                     
              </pages>

That will add an implicit import for all your pages.

For C# it can be a little more complicated. Because you do not have modules like in VB.NET, what you can do is use extension methods, to have a similiar syntax.