从webconfig中获取数据

时间:2017-05-30 12:21:41

标签: javascript web-config

我可以在脚本中的webconfig中显示fttproot和httpserver值吗?如果是这样,我该如何展示呢?你能帮忙吗?



<configuration>
  <appSettings>
    <add key="datapath" value="C:\Mikromax" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
    <add key="ftpserver"  value="212.58.14.178" />
    <add key="ftpuser"  value="admin" />
    <add key="ftproot"  value="Download" />
    <add key="ftppass"  value="mmx-ftp" />
  
  </appSettings>
</configuration>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:1)

您可以将此值注入aspx,如下所示:

<script>
    var ftpRoot = '<%=System.Configuration.ConfigurationManager.AppSettings["ftproot"]%>';
    var ftpServer = '<%=System.Configuration.ConfigurationManager.AppSettings["ftpserver"]%>';
    var apiUrl = '<%=System.Configuration.ConfigurationManager.AppSettings["datapath"]%>';
</script>