Reading web.config values in Classic ASP

asp-classicweb.config

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

Best Answer

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.

Related Topic