简体   繁体   English

在AngularJS项目中访问.net Web.Config

[英]Accessing .net Web.Config in AngularJS project

I have an AngularJS project in "empty" type .net project, which is hosted on IIS with .Net 4.0 framework. 我有一个“空”类型的.net项目的AngularJS项目,该项目托管在带有.Net 4.0框架的IIS上。 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. 我基本上不使用任何.net dll,但由于项目具有web.config文件,因此我添加了一些要在项目中使用的App设置。 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"]). 有没有办法从AngularJS访问.net web.config文件中的AppSettings,因为我没有使用MVC项目,所以不能使用剃刀(@ System.Configuration.ConfigurationManager.AppSettings [“ url”])。

Is there another way to this? 还有另一种方法吗?

Thanks 谢谢

You don't. 你不知道

The Web.Config file is a server-side configuration file, AngularJS is a client-side framework. Web.Config文件是服务器端配置文件,AngularJS是客户端框架。

You can't access it from the browser, because IIS will never - for security reasons - serve it to clients. 您无法从浏览器访问它,因为出于安全原因,IIS永远不会将其提供给客户端。

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. 您可能需要公开一个WebApi控制器或MVC控制器,该控制器返回表示web.config文件的JSON ...或者至少是包含要发送到客户端的web.config文件中的数据的JSON对象。 The WebApi controller would read from web.config via configuration manager, convert to JSON, and send to client. WebApi控制器将通过配置管理器从web.config中读取,转换为JSON,然后发送给客户端。

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. 我正在做类似的事情,将我的角度应用程序需要的服务端点存储在web.config中,但是我想基于调试,开发,登台,生产等方式转换.config文件。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM