简体   繁体   English

Javascript是否可以从web.config AppSettings获得价值?

[英]Can Javascript get value from web.config AppSettings?

I have an aspx page, without the code behind cs file. 我有一个aspx页面,没有cs文件后面的代码。

therefore, if I wanted to get the value from web.config AppSetting, 因此,如果我想从web.config AppSetting获取值,

is it possible to do this in JavaScript or jQuery? 是否可以在JavaScript或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. IIS锁定了配置文件,因此无法直接访问。 You will have to go via Ajax to the server and request the setting. 您将必须通过Ajax进入服务器并请求设置。

Use this to make the call to the server asynchronously 使用它来异步调用服务器

http://api.jquery.com/jQuery.ajax/ http://api.jquery.com/jQuery.ajax/

You will need either a Web Method/ Service / Controller Action (if MVC) to handle the incoming request. 您将需要Web方法/服务/控制器操作(如果是MVC)来处理传入的请求。

Alternatively send the value down in the initial page request via a hidden field or JavaScript variable set. 或者,通过隐藏字段或JavaScript变量集在初始页面请求中向下发送该值。

I would add a asp Hidden field and then set its value on page load from web.config. 我会添加一个“ asp隐藏”字段,然后在从web.config加载页面时设置其值。 You can access that information from JQuery. 您可以从JQuery访问该信息。

The answer is here : 答案在这里:

Can i read data from web.config using JQuery? 我可以使用JQuery从web.config中读取数据吗?

"Jquery is javascript that runs in your browser, your web.config resides on your server..." “ jQuery是在您的浏览器中运行的javascript,您的web.config位于您的服务器上...”
The simple answer is : Not directly , you will have to call a webSerivce method . 简单的答案是:不是直接,您将必须调用webSerivce方法。
It is common that you get the web.config parameters in your code behind. 通常在代码后边获取web.config参数。

由于相当明显的安全原因,IIS默认情况下不会提供Web.Config(或其他文件类型的选择),因此您需要通过Ajax调用或类似方法将应用程序设置返回给jQuery。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM