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
Post a Comment