从Classic ASP站点的aspx页面读取web.config值 [英] Read the web.config value from the aspx page in Classic ASP site

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

问题描述

我有一个asp网站。我也有一些aspx并将这些页面放入asp站点。现在我可以通过asp站点访问这些页面了。但是,有一些页面正在从web.config值获取连接字符串或一些AppSetting键值。



I have an asp site. I have some aspx also and put those pages into the asp site. Now I am able to access those pages through the asp site. However, there are some pages those are fetching the connection string or some AppSetting key-values from the web.config value.

connectionString = 
  Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["ConnString"]);







但是一旦我访问这些页面就会显示错误






But as soon as I access those pages it shows the error

The ConnectionString property has not been initialized.





I已将以下代码放在home.aspx页面中并在浏览器中调用该页面。但它没有显示任何价值。





I have put the following code in the home.aspx page and called the page in the browser. But it does not show any value.

<% Response.Write(Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["ConnString"]);) %>





请告诉我如何通过asp站点内的aspx页面访问web.config文件值。 web.config文件和这些页面位于同一根文件夹中。 IIS中是否有任何设置?



Please let me know how to access the web.config file values through the aspx page those are inside of the asp site. The web.config file and those pages are on the same root folder. Is there any setting in the IIS?

推荐答案

您好,



首先在Web中定义您的值。按以下代码配置,

Hello,

First define your value in web.config as per below code,
<configuration>
<appsettings>
<add key="Connstring" value="your value" />
</appsettings>
</configuration>





然后在aspx.cs页面中写下以下代码,



Then write below code in your aspx.cs page,

string Connstring = System.Configuration.ConfigurationManager.AppSettings["Connstring"];


这篇关于从Classic ASP站点的aspx页面读取web.config值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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