How do I use a web.config key in the controller?

Asked

Viewed 110 times

1

On my web.config I have the following key:

<appSettings>
    <add key="teste" value="teste"/>
<appSettings>

What I need to do to use this key in my controller?

  • Could you be more specific about what you really want to do? You put as tag Angularjs but use it in what way? in what scenario?

  • @Felipe I have several ajax requests in my controllers, which call a URL that starts with the IP and port number (which are fixed to all URL’s). But this fixed start I need to put in a variable, so when someone else is using my project and has to change ip or port, change only in one place. A friend of mine suggested to put it on web.config, as shown above, but I don’t know how to use this key in the controller

  • You refer to Angularjs controllers, or the project that receives the requests, web.config is your project’s configuration file . net?

  • @Felipe I mean the controller of Angularjs. Yes

  • 1

    The web.config you used in your tag is the project configuration file. NET, if we’re only talking about Angularjs(front-end) you can do 2 things: One is to create a JS constant that will be used by all javascript code ,the other is you make one more ajax call to an ASP.NET project controller or another api that you can access, that has in the configuration files the key to create. To read from web.config in the ASP.NET controller you can use the Webconfigurationmanager.Appsettings["test"] command to get the key value set in XML

  • It is important to define the scenario you have, if you have the front-end project and also the back-end, we can treat the possibility of parameterizing this in the settings file of the back-end project, if you only have the Angularjs project , what we can do is define a constant with the necessary value.

  • @Felipe I am responsible for the front, my colleague for the back, he creates the services and I make the consumption. When I showed what was already done for the client’s T.I area, they suggested that I put the beginning of the URL I call in ajax into a variable, all through the Angularjs web.config, so that if they needed to make any changes, would not need to enter controller by controller, but only by the web.config file.

  • I’m new in the field, work with web development is not even 1 year, so I don’t have much knowledge. I believe this web.config that I refer to, is the configuration file so I can open the site by IIS

  • By default, Angularjs does not exist unless you create the web.config file. Create an Angularjs module that will be used by all the code. This link contains the example. https://answall.com/questions/134871/constante-vis%C3%Advel-em-toda-a-aplica%C3%A7%C3%A3o

Show 4 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.