简体   繁体   中英

Web.config - read applicationSettings

I am using VS2015, C#.

I've created a couple of settings via project properties - settings. Some of them are saved here:

  <configSections>
    <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
      <section name="Calendar.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    </sectionGroup>
  </configSections>


<applicationSettings>
    <Calendar.Properties.Settings>
      <setting name="RedirectUriDEBUG" serializeAs="String">
        <value>https://localhost:44367/Login/RedirectGoogle</value>
      </setting>
      <setting name="RedirectUriPRODUKCIJA" serializeAs="String">
        <value>https://ztest30.franjobrekalo.com/Login/RedirectGoogle</value>
      </setting>
      <setting name="LogPathDEBUG" serializeAs="String">
        <value>C:\Users\Frenky\Desktop\AdministrationLog.txt</value>
      </setting>
      <setting name="LogPathPRODUKCIJA" serializeAs="String">
        <value>h:\root\home\frenkyb-001\www\administration\AdministrationLog.txt</value>
      </setting>
      <setting name="LogPathTEST" serializeAs="String">
        <value>h:\root\home\frenkyb-001\www\testnotes\AdministrationLog.txt</value>
      </setting>
    </Calendar.Properties.Settings>
  </applicationSettings>

ApplicationSettings section was generated by visual studio. Now I need to read from applicationSettings. I've tried numerous solutions, to my surprise, nothing worked. It seems that reading from appSettings is easy or from connectionStrings. Why is the problem with generated applicationSettings section?

EDIT:

Problem is with applicationSettings not with appSettings.

You can use ConfigurationManager class.

Try: ConfigurationManager.AppSettings . For detailed info check out msdn .

EDIT: Check out this link once. It seems you cannot use inbuilt API's for ApplicationSettings. It only works for appSettings and connectionStrings. For your case you need to implement a custom class as explained in the above link.

Look for the KEY 'RedirectUriDEBUG' in all your project code... and Visual Studio will find a reference...

It should be somtething like

global::[YOUR_PACKAGE_NAMESPACE].Properties.Settings.Default.[YOUR_KEY] Hope it helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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