How to include adovbs.inc file in an aspx page?

2020-04-18 08:40发布

问题:

I'm converting ASP classic page to ASP.NET. What's the proper way of including files with .inc extension to aspx pages?

<!--#include virtual = "adovbs.inc" -->

I've notice that each time that I change one of those pages containing the include directive pointing to .inc files to aspx, I'm getting all sort of errors from those .inc files.

I feel like just rewriting the logic inside those .inc files into vb classes.

回答1:

The purpose of adovbs.inc or adovbs.asp was to provide a list of named constant values from the ADODB DLL (due to Classic ASP relying on late binding in VBScript for most of it's functionality).

Example snippet of adovbs.asp

'--------------------------------------------------------------------
' Microsoft ADO
'
' (c) 1996-1998 Microsoft Corporation.  All Rights Reserved.
'
'
'
' ADO constants include file for VBScript
'
'--------------------------------------------------------------------

'---- CursorTypeEnum Values ----
Const adOpenForwardOnly = 0
Const adOpenKeyset = 1
Const adOpenDynamic = 2
Const adOpenStatic = 3

'---- CursorOptionEnum Values ----
Const adHoldRecords = &H00000100
Const adMovePrevious = &H00000200
Const adAddNew = &H01000400
Const adDelete = &H01000800

This was until people realised you could use the METADATA data tag to import DLL constants direct from the Type Library instead of needing the adovbs include file.

<!-- METADATA 
        TYPE="typelib" 
        UUID="00000200-0000-0010-8000-00AA006D2EA4"
-->

In ASP.Net everything is compiled so there is no need for these constant files as they will already exist in some form in ADO.Net.



回答2:

If your question is specifically about adovbs.inc then @Lankymart's answer is spot on. I'd add that the file is written in VBScript (as its name suggests) so it would be no use in asp.net, which doesn't use VBS.

If you're asking about include files in general then asp.net does support the #include directive. The file extension .inc makes no difference, if you're including it in a .asp file then it needs to contain code which is compatible with Classic ASP, if it's included in a .aspx file then it needs to contain code compatible with asp.net.

Practically, this means that if you have say, header and footer include files which contain only client side code then you could use them in either a Classic or a .net page. If they contain server side code then you can't transfer them

It's possible to construct an .aspx page in the style of a Classic ASP page, eg

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


    <!--#include virtual = "header.inc" -->

    <%
      // Put some C# code here
    %>

    <!--#include virtual = "footer.inc" -->

There are however, much better ways of building an asp.net file. I assume that one of the reasons you're converting is so that you can use Master pages, codebehinds etc.