从 asp.net 中读取 webConfigurationManager.AppSettings

read webConfigurationManager.AppSettings from asp.net

我有一个 asp.net 页面,我需要从 web.config 读取一些 appSetting 值。谷歌搜索后,我发现我可以使用这段代码:

using System.Web.Configuration;

WebConfigurationManager.AppSettings["configFile"]

但是在我使用 System.Web.Configuration 插入行之后,在我的 aspx 页面

中输入
<%@ Using System.Web.Configuration; %>

我收到此错误:ASP.net 运行时错误。在包含内容控件的内容页面中只允许直接使用内容控件。那么,如果它不允许我导入 System.Web.Configuration,我该如何从我的 asp 页面读取系统 Web 配置文件?

我认为这应该可以解决问题(我从未使用过 WebConfigutationManager,但这对我有用)。

代码隐藏

using System.Configuration

protected string GetForgottenUrl()
{
  return ConfigurationManager.AppSettings["SomeKey"];
}

Aspx 页面

<a href='<%= GetForgottenUrl()%>'>Forgot Password</a>

Web.Config

<configuration>
  <appSettings>
     <add key="SomeKey" value="SomePage.aspx" />
  </appSettings>
</configuration>

编辑::您可能需要添加对 System.Configuration

的引用