Monday, May 13, 2013

Accessing Web.Config to pass values to silverlight Application

Like we are use to save our application information for example connection string and others. Application needs that configuration information to run a different section of it. Application developer needs to change that information often, but in Silverlight it not possible with traditional way because Silverlight is client side technology so web.config is not accessible directly like in

For Silverlight we need to pass parameter from server side as access them on client side in App.xaml.


1- Add a key and its value in web.config in appSettings section.

2- Add param tags in Default.aspx and Default.html

3- Catch the value in App.xaml in Application_Startup function.

4- Now you can set this value anywhere in application by using this code.

if (Application.Current.Host.InitParams.ContainsKey("BingMapKey"))
BingMap.CredentialsProvider = new ApplicationIdCredentialsProvider(Application.Current.Host.InitParams["BingMapKey"]);

No comments:

Post a Comment