Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading web.config values in Classic ASP

I have inherited a legacy classic asp site that I need to support, and am in the process of setting up a dev/debugging environment so I don't have to work on the production server.

The code is a bit of a mess, and there are literaly hundreds of connection strings dotted around the place in various .asp files. These all contain hard-coded references to the SQL server, etc.

I really don't want to have to replace all of these with my local dev environment SQL DB settings, so I was wondering if there was an easy way to get classic asp to read from a .net web.config file. This way I could change all of the hard-coded connection strings to read from this one place, and then I only need to define the server details in one place.

This would mean that I could then write code & debug locally, and all I would have to do is change a couple of values in the web.config before deployment.

Please provide clear examples in your answer, as I'm new to classic asp & I'm really not liking it at this stage. Can't wait to redevelop it all in .net ;)

Thanks

like image 587
Bob Avatar asked Aug 31 '11 10:08

Bob


2 Answers

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

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

You can then use application("connectionstring") on every page without having to have an include on the page.

like image 167
Erik Oosterwaal Avatar answered Nov 09 '22 23:11

Erik Oosterwaal


Just use a server-side-include with all the app settings you need. It will be much easier (and faster) to implement than reading a 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 tell you could improve the rest of your heritage using SSI in other places too.

like image 26
Filburt Avatar answered Nov 10 '22 00:11

Filburt