I have an aspx page, without the code behind cs file.
开发者_如何学Pythontherefore, if I wanted to get the value from web.config AppSetting,
is it possible to do this in JavaScript or jQuery?
Appreciate if you could provide me some references, thank you.
Not directly. The config files are locked down by IIS so direct access is impossible. You will have to go via Ajax to the server and request the setting.
Use this to make the call to the server asynchronously
http://api.jquery.com/jQuery.ajax/
You will need either a Web Method/ Service / Controller Action (if MVC) to handle the incoming request.
Alternatively send the value down in the initial page request via a hidden field or JavaScript variable set.
IIS by default will not serve Web.Config (or a selection of other file types as well) for reasonably obvious security reasons so you'd need to return your application setting to jQuery via an Ajax call or similar.
I would add a asp Hidden field and then set its value on page load from web.config. You can access that information from JQuery.
The answer is here :
Can i read data from web.config using JQuery?
"Jquery is javascript that runs in your browser, your web.config resides on your server..."
The simple answer is : Not directly , you will have to call a webSerivce method .
It is common that you get the web.config parameters in your code behind.
精彩评论