2010-08-02 86 views

回答

8

您可以在页面的标记使用下面的代码:

<script language="JavaScript" type="text/javascript"> 
var type = '<%= ConfigurationManager.AppSettings["imagetype"] %>'; 
</script> 
1

使用以下命令:

var value = System.Configuration.ConfigurationManager.AppSettings["imagetype"]; 

您可能会发现,它的工作,你需要添加一个引用到System.Configuration.dll,如果你不已经有一个。

创建一个新的页面,并在Page_Load中放线,使这一切写着:

Response.Clear(); 
var value = System.Configuration.ConfigurationManager.AppSettings["imagetype"]; 
Response.Write(value); 
Response.End(); 

您现在可以从Javascript使一个AJAX调用的页面,也许using ExtJs和文本将返回你的JavaScript。

或者,你可以把下面的到你的页面:

<script language="javascript" type="text/javascript"> 
    var appSettingValue = '<%=System.Configuration.ConfigurationManager.AppSettings["imagetype"]%>'; 

    // The variable "appSettingValue" will contain the string from your web.config 
    alert(appSettingValue); 
</script> 
+1

这是MVC ... ...有没有...的Page_Load – 2010-08-02 14:29:07

+0

@ŁukaszW.pl,是的,但一般的要点是一样的。出于某种原因,我的眼睛在“asp.net”之后停止阅读 - 今天是漫长的一天! =) – Rob 2010-08-02 14:35:10