1

I have an AngularJS project in "empty" type .net project, which is hosted on IIS with .Net 4.0 framework. I basically don't use any .net dlls but since the project has a web.config file i add some App setting to use in the project. Trying to set development/production setting.

Is there a way to access AppSettings in the .net web.config file from AngularJS, because i am not using a MVC project, I can't use razor (@System.Configuration.ConfigurationManager.AppSettings["url"]).

Is there another way to this?

Thanks

4
  • no, you can't, but behind that case, what would you like to do? Commented Oct 2, 2014 at 14:27
  • long story short: no. web.config is protected outside of .NET environment. Commented Oct 2, 2014 at 14:27
  • You can't but presum,ably you just want to access the values from the config. There is nothing stopping you writing some kind of service that returns whatever config settings you want, you can then call this service from angular. Commented Oct 2, 2014 at 14:29
  • I was thinking in the sense of before the server sent the javascript file to the client, replace the variables with webConfig variables: something like razor with MVC -> url: "@System.Configuration.ConfigurationManager.AppSettings["url"]" If that makes sense. Commented Oct 2, 2014 at 14:33

2 Answers 2

8

You don't.

The Web.Config file is a server-side configuration file, AngularJS is a client-side framework.

You can't access it from the browser, because IIS will never - for security reasons - serve it to clients.

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

2 Comments

As an addendum, you could server up an ASP page with WebMethods (accessible through AJAX), which would be your only dependency if you chose that route.
@BradChristie yes, you can create something that reads the Web.Config and send it to the client, but it would be criminal (at least). A single "page" fetching a configuration section would be better.
4

You may want to expose a WebApi controller or MVC controller that returns JSON that represents web.config file... or at least the JSON object that has the data in the web.config file you need to send to client. The WebApi controller would read from web.config via configuration manager, convert to JSON, and send to client.

I am doing something similar where I am storing my service endpoints that my angular app needs in my web.config, but I want to transform the .config files based upon debug, dev, staging, production etc.

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.