How to configure Web.config in Cordova project?

Asked

Viewed 157 times

2

In that question I was recommended to configure the web.config of my project Cordova that uses Ajax. I searched on the subject but found nothing of the kind. Someone can help me?

1 answer

0


Define in your Web.config the following:

<configuration>
  ...
  <appSettings>
    ...
    <add key="BaseURL" value="http://localhost:12345/" />
  </appSettings>
</configuration>

Retrieving the information:

using System.Configuration;

var baseUrl = ConfigurationManager.AppSettings["BaseURL"];

When deploying, the information can be changed through transformation files. In the project, two are created as an example: Web.debug.config and Web.Release.config. In case, to change BaseURL, configuration is as follows for a file Web.Release.config:

<?xml version="1.0"?>

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <appSettings>
    <add key="BaseURL" value="http://urldomeusite.com.br" xdt:Transform="SetAttributes" xdt:Locator="Match(key)" />
  </appSettings>
  <system.web>
    <compilation xdt:Transform="RemoveAttributes(debug)" />
  </system.web>
</configuration>
  • Thanks again for the reply @Gypsy, in that comment explain my password better. The project in Ordova can be found here. I didn’t mean well, but these settings should do in my Asp.Net MVC project?

  • @Jedaiasrodrigues Yes, exactly. As the configuration is variable, when publishing the project, the Web.config will be changed automatically.

  • But doesn’t that bring risk to the rest of my project? And in my Cordova project I don’t need to do anything?

  • What risks? Could you show me?

  • Well what basically makes this change?

  • As I told you, the configuration makes it possible for you to use variable values for configuration of, for example, the base URL of your application. When sending to production, it is obvious that an address based on localhost won’t work.

  • Friend, suppose I have a . html file that I just created in the notepad with an Ajax code to get the data generated by this application. I put a breakpoint in the application and the request is coming normally, but after that the Ajax error message is generated, what could it be? You would have an example to get the data from the cited link?

  • Please ask another question.

  • The new question was asked at this link.

Show 4 more comments

Browser other questions tagged

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