Click here to Skip to main content
15,895,084 members
Articles / Web Development / XHTML

Configure Silverlight 3 Applications using the Web.config File from ASP.NET

Rate me:
Please Sign up or sign in to vote.
4.43/5 (19 votes)
6 Jan 2010CPOL7 min read 114.1K   995   27  
This article introduces a method to configure Silverlight 3 applications using the Web.config file from ASP.NET.
using System;
using System.Web;
using System.Text;
using System.Collections.Specialized;
using System.Configuration;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SilverlightConfigurationDemoWeb
{
    public partial class Default : System.Web.UI.Page
    {
        private void SaveSilverlightDeploymentSettings(Literal litSettings)
        {
            NameValueCollection appSettings = ConfigurationManager.AppSettings;

            StringBuilder SB = new StringBuilder();
            SB.Append("<param name=\"InitParams\" value=\"");

            int SettingCount = appSettings.Count;
            for (int Idex = 0; Idex < SettingCount; Idex ++)
            {
                SB.Append(appSettings.GetKey(Idex));
                SB.Append("=");
                SB.Append(appSettings[Idex]);
                SB.Append(",");
            }
            SB.Remove(SB.Length - 1, 1);
            SB.Append("\" />");

            litSettings.Text = SB.ToString();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            SaveSilverlightDeploymentSettings(ParamInitParams);
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
I have been working in the IT industry for some time. It is still exciting and I am still learning. I am a happy and honest person, and I want to be your friend.

Comments and Discussions