Azure class library access GetConfigurationSettingValue vs. web.config

雨燕双飞 提交于 2019-12-04 06:35:35

Create your own class to retrieve configuration values and in it you'll have items like this:

if (RoleEnvironment.IsAvailable)
 return RoleEnvironment.GetConfigurationSettingValue("mySetting");
else
 return ConfigurationManager.AppSettings["mySetting"].ToString();

RoleEnvironment.IsAvailable will detect is supposed to detect if you're in the Windows Azure fabric and return true. It will require that you include the Microsoft.WindowsAzure.ServiceRuntime assembly/referrence in your ASP.NET project.

I did a blog post on this topic if you want more information.

This is now built-in to the latest Azure SDK. You can use the CloudConfigurationManager.GetSetting("") method, it determines if you are running in the cloud or not and reads from one or the other. This is the replacement for the RoleEnvironment azure class.

http://msdn.microsoft.com/en-us/library/microsoft.windowsazure.cloudconfigurationmanager.aspx

If you are utilizing nuget, the nuget package name is Microsoft.WindowsAzure.ConfigurationManager

Check out RoleEnvironment.IsAvailable.

You could write a quick "helper" class that branches logic based on if RoleEnvironment.IsAvailable returns true or not. If true, for example, read from web.config and if false, read from the cloud configuration.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!