Javascript文件 - 在运行时从web.config更改源代码

时间:2012-03-14 14:03:14

标签: javascript asp.net

我的代码中有这个:

<script type="text/javascript"
  src="path?key=1234567890">
</script>

我在web.config中添加了这个:

<appSettings>
    <add key="key" value="1234567890"/>

如何在上面的代码中实现它?

1 个答案:

答案 0 :(得分:2)

您使用System.Web.Configuration.WebConfigurationManager.AppSettings集合来访问配置设置。

<script type="text/javascript"
        src="path?key=<%=WebConfigurationManager.AppSettings["key"]%>">
</script>