How to Read Web.config file (Key value) from JS in HTML using ASP.Net

Posted by Vishnupavadi under ASP.NET on 3/18/2014 | Points: 10 | Views : 18658 | Status : [Member] | Replies : 4
Hi Guys,
In my asp.net application, there is one HTML page. Already it has huge content. Now, we gotta requirement to show the application version in that HTML Page. Application version will be keep on changing frequently. Application version already in web.config file in appsetting -

<appSettings>
<add key="Version" value="Ver.15.9.4.56"/>
</appSettings>


Now I want to show that Key value from web.config in HTML page. Yes, I know using Javascript we can achieve it.
But I tried a lot am not able to access it using JS.

As my experience using JS we can access only in ASPX page not in HTML page. All the way I tried whatever stuffs got in googling. But No solution.

But I don't want to convert from HTML page to aspx page.

Please anybody help me out, Is there anyway to achieve this.
Thanks a lot in advance. awaiting for the response.




Responses

Posted by: Jayakumars on: 3/19/2014 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi

try this one

var version= "<%= ConfigurationManager.AppSettings["Version"].ToString() %>";


Mark as Answer if its helpful to you

Vishnupavadi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Allemahesh on: 3/19/2014 [Member] [MVP] Silver | Points: 25

Up
0
Down
Jut do the below steps:-

1. Insert an hidden field on page.
2. Load/Save the key values to this hidden field on page load event.
3. Read the key values form this hidden field.

Happy coding.

Vishnupavadi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vishnupavadi on: 3/21/2014 [Member] Starter | Points: 25

Up
0
Down
HI Allemahesh, thanks for your response. As I told earlier, its basic html page, not aspx page to use coding. I want to achieve this using JavaScript.

Hi Jayakumars, very much thanks for your suggestion. I tried this before I posting here, it won't work as it is basic html page in asp.net.

HTMLPage.htm
-----------
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript">
function bringvalue() {
var version = "<%= System.Configuration.ConfigurationManager.AppSettings['WebVersion'].ToString() %>";
alert(version);
}
</script>
</head>
<body>
<input type="button" value="Click Here" onclick="bringvalue();" />
</body>
</html>



Please let me know. Is there possible to do it or not.
Thanks a lot in advance.

Vishnupavadi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: A2H on: 3/22/2014 [Member] [MVP] Silver | Points: 25

Up
0
Down
Hi,
AFAIK there is not direct solution to read the config values in HTML Page. However as a workaround You can try the solution suggested in below link

http://stackoverflow.com/questions/10118165/how-to-read-web-config-settings-in-html-page

Please mark my reply as answer if it answer your question

Thanks,
A2H
My Blog

Vishnupavadi, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response