Reading web.config values ​​in classic ASP

I inherited an outdated classic asp site that I need to maintain, and I'm in the process of setting up a dev / debugging environment, so I don’t have to work on a production server.

The code is a bit of a mess, and there are literally hundreds of connection strings placed around a place in various .asp files. All of them contain hard-coded links to the SQL server, etc.

I really don't want to replace all of these local developer SQL DB database options, so I was wondering if there is an easy way to get the classic asp to read from the .net web.config file. That way, I could change all the hardcoding lines to read from this one place, and then I only need to determine the server data in one place.

This would mean that I could then write code and debug locally, and all I need to do is change a couple of values ​​in web.config before deploying.

Please provide clear examples in your answer, since I am new to classic asp, and I really don't like this. I can not wait to redo all this in .net;)

thanks

+7
source share
2 answers

Just use the server side with all the application parameters that you need. It will be much easier (and faster) to implement than reading web.config and give you the same flexibility.

config.asp

<% Dim connectionString connectionString = "your connectionstring here" %> 

Default.asp

 <% Option Explicit %> <!-- #include virtual="config.asp" --> <% '--- ' ... use connectionString here '--- %> 

From what you say, you can improve the rest of your legacy by using SSI in other places.

+5
source

The usual place for this in classic ASP is the application variable in the global.asa file:

 SUB Application_OnStart application("connectionstring")= "[your connectionstring]" END SUB 

Then you can use application("connectionstring") on each page without having to include on the page.

+20
source

All Articles