Asp.net mvc c # javascript web.config

I want to get "imagetype" from application settings in my web.config in javascript. How can i do this?

+5
source share
2 answers

You can use the following code in your page layout:

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

Use the following:

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

You may find that for it to work you need to add a link to System.Configuration.dllif you do not already have it.

Create a new page, and in Page_Load place the line so that it reads everything:

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

Now you can make an AJAX call on the page from Javascript, possibly using ExtJs , and the text will be returned to your 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

All Articles