AllPower
AllPower

Reputation: 195

ASP.NET MVC - Change appsettings tag location from webConfig

I will need to remove the appsettings tag from the webconfig and put it elsewhere, but how do I find this new location in the code?

My app settings:

<appSettings>
    <add key="ClientValidationEnabled" value="true" />
    <add key="TimeEditDeleteApont" value="180" />
    <add key="TimeStockApont" value="180" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
    <add key="AdminUserName" value="[email protected]" />
    <add key="AdminPassword" value="Password#1" />
    <add key="TempUploadFolder" value="~/content/upload/temp" />
    <!--<add key="FinalUploadFolder" value="~/content/images/apontamento" />-->
    <add key="AllowedFiles" value=".ppt,.pttx,.pdf,.jpeg,.jpg,.gif,.png,.doc,.docx,.xls,.xlsx" />
    <add key="MaxFileSizeMegaByte" value="25" />
  </appSettings>

How i use inside my code:

  public BaseController()
        {
            ViewBag.FinalUploadFolder = System.Configuration.ConfigurationManager.AppSettings.Get("FinalUploadFolder");
            ViewBag.TempUploadFolder = System.Configuration.ConfigurationManager.AppSettings.Get("TempUploadFolder");

        }

public string TimeConfig
        {
            get
            {

                return ConfigurationManager.AppSettings["TimeEditDeleteApont"];
            }
        }

How can I change the location of appSettings and then find that location within the code?

After I create a config file at the root of the folder, how do I find it inside the code?

Upvotes: 0

Views: 220

Answers (1)

AllPower
AllPower

Reputation: 195

In case somebody needs to separate the <appSettings> from the webConfig file, I did it as follows:

I created a appSettings.config file at the root of the project and then at <appSettings> I pointed to this file as follows:

<appSettings 
    configSource="appSettings.config">        
</appSettings>

Upvotes: 1

Related Questions