views:

293

answers:

2

We are porting a Classic ASP app to ASP.NET. What do we do about the #INCLUDE (.inc) files? Now they're causing build errors because ASP.NET thinks the variables are "not declared".

+2  A: 

You haven't stated what is in the .inc files. Lets assume there are a bunch of const definitions and a few helper functions.

There are a couple of variations that you might consider.

  1. Often there is a single .inc which gets included in all or most ASP pages.
  2. Other .inc files get included in a few ASP pages because they just encapsulate some shared functionality.

For variation 1 it might help to create a class that derives from Page that exposes the original .inc files constants as properties and its functions as methods. Have all the ported ASP to ASP.NET pages inherit from this new class rather than directly from Page.

For variation 2 create classes in App_Code that contain static properties and methods (or direct ports of VBScript classes if that's what the .inc contained). The ASP to ASP.NET page ports that use these includes would need to prefix their usage of members from the original .inc file with the name of the class of which they are not static (shared) members.

If the includes originally contain static markup then a better port for those is to create representative .master pages and have the ported ASP pages use those masters appropriately.

AnthonyWJones
The .inc files include just about everything: subroutine declarations; "global" variable initializations (and sometimes declarations); code that just runs at the time of the include, complete with conditional logic that checks Session variables and conditionally redirects and/or includes other files...
JoelFan
@JoelFan: The amount of code and additional includes isn't really an issue the same principles hold. ASP.NET simply does not have a lexical include like ASP has, it isn't necessary. Unlike ASP, ASP.NET can access code external to the file by simply adding compiled assemblies to the bin folder or dumping code files into the app_code folder. You can also place in the App_Code folder class files that you can have your pages inherit from. You can also use .master pages. You just need to divide up the contents of the include files across these different approaches according to the best fit.
AnthonyWJones
Just what I would have suggested: custom base page class and master page for common functionality and markup.
Grant Palin
+1  A: 

You can port them in the same way you did in ASP:

 <!--#include virtual="/include/flash-check_inc.asp"-->
nrose101
What does that do in ASP.NET?
John Saunders
It will include the file in the virtual directory /include/flash-check_inc.asp. It is simply a port from the classic asp and still can be used in the code.
nrose101
Have you actually tried this? I'd be really surprised to see this work.
AnthonyWJones
100% I still have some legacy code that has been using it for a couple of years.
nrose101