在经典 ASP 中读取 web.config 值 [英] Reading web.config values in Classic ASP

查看:31
本文介绍了在经典 ASP 中读取 web.config 值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我继承了一个需要支持的传统经典 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.

代码有点乱,实际上有数百个连接字符串散布在各种 .asp 文件中.这些都包含对 SQL 服务器的硬编码引用等.

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.

我真的不想用我的本地开发环境 SQL DB 设置替换所有这些,所以我想知道是否有一种简单的方法可以让经典的 asp 从 .net web.config 文件中读取.这样我就可以将所有硬编码的连接字符串更改为从这个地方读取,然后我只需要在一个地方定义服务器详细信息.

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.

这意味着我可以编写代码 &在本地调试,我所要做的就是在部署之前更改 web.config 中的几个值.

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.

请在您的回答中提供清晰的示例,因为我是经典 asp 的新手在这个阶段我真的不喜欢它.迫不及待地想在 .net 中重新开发它;)

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 ;)

谢谢

推荐答案

只需使用服务器端包含您需要的所有应用程序设置.实施起来会比阅读 web.config 更容易(也更快),并为您提供同样的灵活性.

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
'---
%>

根据您的说法,您也可以在其他地方使用 SSI 来改善您的其他遗产.

From what you tell you could improve the rest of your heritage using SSI in other places too.

这篇关于在经典 ASP 中读取 web.config 值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆