asp.net web api - Can't get Empty WebAPI project to read web.config setting -


i created empty webapi project vs 2013. added following web.config:

in controller class, trying read setting , null exception.

    public bool getconnstring(string basecode, string scope)     {          try         {              string connstring = system.configuration.configurationmanager.connectionstrings["isroak1"].tostring();           }         catch (exception ex)         {             string msg = ex.message.tostring();         }          return true;     } 

i tried again create new empty webapi project , same null exception thrown. think empty webapi missing something. how can fix read conn string setting?

thanks help.

try this:

system.configuration.configuration rootwebconfig1 = system.web.configuration.webconfigurationmanager.openwebconfiguration(null); if (rootwebconfig1.appsettings.settings.count > 0) {     system.configuration.keyvalueconfigurationelement customsetting = rootwebconfig1.appsettings.settings["isroak1"]; } 

the setting need in app setting node in web.config


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -