Best way to manage connection strings in a project that contains both classic ASP and ASP.Net 1.1 code?

I have a project that I inherited, this is, first of all, the Classic ASP application; however, mixed in the application are several ASP.net pages. Some ASP.net pages are 1.1 and do not use code behind the model.

There are several / include directories on classic ASP pages where there is a file for connecting to the database. ASP.Net pages are line encoded in their code.

I am trying to clear this mess of connection strings to simplify management in development environments.

Does anyone have any recommendations on how I can effectively do this, which will work for both ASP and ASP.Net pages?

thanks

+3
source share
3 answers

Put the web.config file in the root of the classic asp site. ASP.net pages without code (and without any virtual directories / applications anywhere) will use this web.config file. You can set connection strings there. You will probably have two sets of strings, but this is better than many others. And if you really want this, you can write some classic asp code to read this configuration file.

+2
source

This method focuses on extracting the connection string file from webroot for the source code version control system (e.g. svn).

Files:

c:\inetpub\config\config.xml
c:\inetpub\wwwroot\global.asa
c:\inetpub\wwwroot\onInit.asp

config.xml:

<?xml version="1.0" encoding="utf-8" ?>
<root>
  <database
      ip="XXXX"
      catalog="XXXX"
      id="XXXX"
      password="XXXX"
    />
</root>

global.asa:

<script runat="Server" language="VBScript">
    Sub Application_OnStart()        
        server.execute("/onInit.asp")
    End Sub

    Sub Application_OnEnd()
    End Sub
</script>

onInit.asp:

<% 

    dim xmlDoc, xmlPath, objNodes
    set xmlDoc = server.CreateObject("microsoft.xmldom")
    xmlDoc.async = false        
    xmlPath = Server.MapPath("/")
    xmlPath = left(xmlPath, inStrRev(xmlPath, "\")) & "config\config.xml"
    xmlDoc.load xmlPath

    set objNodes = xmlDoc.selectNodes("//database") 

    application("connectionString") = "Provider=SQLOLEDB.1;Persist Security Info=True;"_
        & "Data Source="     & objNodes.item(0).getAttribute("ip") & ";"_ 
        & "Initial Catalog=" & objNodes.item(0).getAttribute("catalog") & ";"_
        & "User ID="         & objNodes.item(0).getAttribute("id") & ";"_
        & "Password="        & objNodes.item(0).getAttribute("password")

    set objNodes = nothing
    set xmlDoc = nothing  

%>
+1
source

. , , , .

, , . , , , , . , , .

  • , , .
  • asp asp.net ( - , /).
  • , , CSS ..
  • , , . , CSS .., - ..
  • , - CSS, script img, , , .
  • , -, , - .

, , Visual Studio Conversion. VS 2003 VS 2005, VS2008 .

, , . TFS, TFS VS. , Subversion , TFS, , TFS.

0

Source: https://habr.com/ru/post/1720837/


All Articles