[英]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. 就是说,您可能选择创建一个
ashx
或aspx
来读取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.