Sumit Deshpande
Sumit Deshpande

Reputation: 2155

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

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?

Upvotes: 0

Views: 801

Answers (2)

freefaller
freefaller

Reputation: 19963

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.

Upvotes: 2

Patrick Hofman
Patrick Hofman

Reputation: 157038

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.

Upvotes: 4

Related Questions