ARTICLE

Access webconfig appsettings Silverlight Application

Posted by Gomathi Palaniswamy Articles | Silverlight with C# August 18, 2011
In this article we are going to see how to access appsettings in silverlight application.
Reader Level:

Introduction:

In every ASP.Net application we used to access webconfig appsettings key values for use sql connection and other key values which have to be controlled from out of page. So to achieve this in ASP.Net we use the following command

"System.Configuration.ConfigurationManager.AppSettings["ConStr"]"

This gives the value which has been written in webconfig like,

<appSettings file="">
<clear/>
<
add key="ConStr" value="Data Source=DataSourceName;
Initial Catalog=DataBaseName;User ID=UserName;Password=Password
"/>
</appSettings>

But in silverlight application we cant use appsettings as like asp.net application. Because the silver light application is a client side application. So in this article we are going to see how to access appsettings in silverlight application.

Code in WebConfig:

<appSettings file="">
    <clear/>
    <
add key="SampleVal" value="1"/>
 </appSettings>

Here specify which value you are going to use in silver light application.In add tab Key is the name of the key and value is the accessing value of the key.

Pass The config value to aspx page:

To pass the config value add param in silverlight application object.

<param name="initParams" value=" SampleVal =<%= System.Configuration.ConfigurationManager.AppSettings["SampleVal "]%>"/>

To get the value in xaml page:

To use the key value in MainPage.xaml first get it in app.xaml and pass it to MainPage.xaml.
In App.Xml get the value by below code.


public string SampleVal ="";
private void Application_Startup(object sender, StartupEventArgs e)
{
                 SampleVal = e.InitParams["SampleVal "];
                this.RootVisual = new MainPage();
}

To use value in MainPage.xaml

App application = (App)Application.Current;
String finalval= application. SampleVal;
 

Login to add your contents and source code to this article
post comment
     

its to change dynamic input..

Posted by Gomathi Palaniswamy Aug 20, 2011

Post your question in Forums section here is the link "http://www.c-sharpcorner.com/Forums/AddPost.aspx?TSource=AddPost"

Posted by Dinesh Beniwal Aug 18, 2011

Is it safe to pass application setting through parameters? Can anyone view those parameters in request/Fiddler?

Posted by vinayak hodage Aug 18, 2011
COMMENT USING
PREMIUM SPONSORS
DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and add new content to existing PDF documents from within your applications.
Join a Chapter
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.