简体   繁体   English

使用Javascript文件读取ASP.Net项目中Web.config的配置设置

[英]Read Configuration Settings of Web.config in ASP.Net project using Javascript File

I want to read Web.Config settings through javascript file. 我想通过javascript文件读取Web.Config设置。
I have below reference link which suggest the same but works ONLY when we add the code in .aspx file and not when put into .JS file. 我在下面的参考链接中提出了相同的建议,但仅当我们在.aspx文件中添加代码时才有效,而在放入.JS文件中时则无效。 http://www.codeproject.com/Tips/77917/Read-Configuration-Settings-of-Web-config-using-Ja http://www.codeproject.com/Tips/77917/Read-Configuration-Settings-of-Web-config-using-Ja

Is it possible to do that with code in .js file? .js文件中的代码可以做到吗?

No, and you shouldn't want to (you can by changing the IIS ISAPI file handler, but NO!). 不,您不希望这样做(可以通过更改IIS ISAPI文件处理程序来实现,但是不可以!)。 The web.config file is a file that needs to be secured heavily, since it can contain usernames and passwords to databases and other resources. web.config文件是一个需要高度保护的文件,因为它可以包含数据库和其他资源的用户名和密码。 The web.config should not be exposed to the outside world! web.config不应暴露于外界!

That said, you might opt to create an ashx or aspx that reads a specific part of the web.config and exposes that to the page, but that is as far as I would go. 就是说,您可能选择创建一个ashxaspx来读取web.config的特定部分并将其显示在页面上,但这已尽我所能。

IIS will never allow the browser to directly request the web.config file... so the simple answer is "No, you can't do that with javascript". IIS绝对不允许浏览器直接请求web.config文件...因此,简单的答案是“不,您不能使用javascript来做到这一点”。

Your only option is to stream the file via an .aspx page (or similar), but I wouldn't recommend it as it could potentially (almost certainly) be a security issue. 您唯一的选择是通过.aspx页(或类似文件)流式传输文件,但我不建议您这样做,因为它可能(几乎可以肯定)是一个安全问题。

Edit: As Patrick says in his answer above, if you need to expose specific parts, then that would be better - but don't expose the entire file. 编辑:正如Patrick在上面的回答中所说,如果您需要公开特定的部分,那会更好-但是不要公开整个文件。

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

相关问题 如何使用ASP.NET MVC4 Razor项目中的web.config文件中的值更新JavaScript? - How to update JavaScript with a value from web.config file in an ASP.NET MVC4 Razor project? web.config中的ASP.NET应用程序设置debug =“ false”会破坏Javascript - ASP.NET Application setting debug=“false” in web.config breaks Javascript ASP.NET - Javascript 超时警告基于 web.config 中的 sessionState 超时警告 - ASP.NET - Javascript timeOut Warning based on sessionState timeOut in web.config 如何使用JS文件中的JavaScript从web.config中读取会话超时值 - How to read Session timeout value from web.config using javascript in JS file 在Asp.net空网站中,如何更改“Web.config”使内容(.js)文件在浏览器中显示而不是下载 - In Asp.net Empty website, How to change “Web.config” to make contents(.js) file displaying in Browser rather than downloading 我可以将配置设置注入javascript吗? - asp.net Can I inject configuration settings into javascript? 如何在Web.Config中不存储ASP.NET站点的配置信息 - How to store config information for a ASP.NET site not in Web.Config 从javascript读取web.config - Read web.config from javascript 从Javascript中读取web.config值 - Read web.config values from Javascript ASP.NET条件标记渲染根据Web.config键 - ASP.NET Conditional Markup Rendering According to Web.config Key
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM