我有一个asp.net页面,需要从web.config读取一些appSetting值。在googling之后,我发现我可以使用以下代码:
using System.Web.Configuration;
WebConfigurationManager.AppSettings["configFile"]但是在我使用System.Web.Configuration插入行之后,在aspx页面输入以下内容
<%@ Using System.Web.Configuration; %>我得到了这个错误: ASP.net运行时错误。只允许在包含内容控件的内容页中直接使用内容控件。那么,如果asp页面不允许我导入System.Web.Configuration,那么如何读取系统web配置文件呢?
发布于 2015-02-10 08:49:45
我认为这应该能起作用(我从未使用过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的引用
https://stackoverflow.com/questions/28426872
复制相似问题