开发者

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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜