Wednesday, February 08, 2012

If you are planning to move your Silverlight application into Window Azure and you have some configuration value which will be used on your application at runtime then you have to read config file value in different way.

If you have normal Silverlight application then it is simple to read value from Web.config file but if you moved your Silverlight application into window Azure then Web.config file cannot be used on Cloud.

In that case you have to call window Azure config file (‘.cscfg’) file from SilverlightTest.aspx file and pass into App.xmal so that it can be used in application. see below picture

Note: IF Project has been deployed into On Premises then read value from Web.Config file, IF Project has been deployed into Window Azure then read value from ServiceConfiguration.Cloud.cscfg and ServiceConfiguration.Local.cscfg files.

Steps-7

Go to Project: SilverlightApplication1.proj and Open App.xaml.cs file and on the Application_Startup() event write following code into it

privatevoid Application_Startup(object sender, StartupEventArgs e)

{

//initialize InitParam value

IDictionary<string, string> initParams = e.InitParams;

//Read value from config

stringvalueFromConfigKey1 = initParams["ConfigKey1"].ToString();

stringvalueFromConfigKey2 = initParams["ConfigKey2"].ToString();

}

Steps-8

Set the Startup project as “WindowsAzureProject.ccproj” and put the break point into Application_Startup() event You will get the value into “valueFromConfigKey1” and 2 variable are

valueFromConfigKey1 = “Get value from Window Azure Config file”

valueFromConfigKey2 = “Text to test”

Steps-9

Set the Startup project as “SilverlightApplication1.Web.proj” and put the break point into Application_Startup() event You will get the value into “valueFromConfigKey1” and 2 variable are

valueFromConfigKey1 = “Get value from On Premises Config file”

valueFromConfigKey2 = “Text to test”

Note: you can add multiple value into "Initparams" in same way as above.