0

I want to read Web.Config settings through javascript file.
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. 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?

2
  • 2
    IIS will never allow the browser to directly request the web.config file. Your only option is to stream the file via an .aspx page (or similar), but I wouldn't recommend it as it could potentially be a security issue Commented May 15, 2015 at 8:01
  • ^^ What freefaller said. You'd have to execute the javascript on the server, it would never work from the client. What are you trying to do exactly, if there's setting you need on the client side there's a multitude of different ways to achieve this. Commented May 15, 2015 at 8:02

2 Answers 2

4

No, and you shouldn't want to (you can by changing the IIS ISAPI file handler, but NO!). 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. The web.config should not be exposed to the outside world!

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.

Sign up to request clarification or add additional context in comments.

Comments

2

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".

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.

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.