This is for Silverlight applications that use the <object> element in its startup page. C# is used in the code snippets from the xaml pages (App.xaml and Page.xaml).
Sorry about the spacing, pasting from VS is not the best. I will post the download link for this solution in about an hour.
First, add an <appSettings> element to your web.config anywhere under <configuration>:
< appSettings>
< add key="RemoteBaseURL" value="http://bobo"/>
< add key="RemoteBasePort" value="9009"/>
< add key="RemoteBaseServiceName" value="EntityService.svc"/>
</ appSettings>
|
Next, in your Silverlight startup page (typically default.aspx) add a <param> element named "initParams" as shown below. You assign the key/value pairs from the <appSettings> in the web.config. Separate each pair with a comma "," .
<param name="initParams" value="<%= string.Format("RemoteBaseURL={0}", ConfigurationManager.AppSettings["RemoteBaseURL"])%>,<%= string.Format("RemoteBasePort={0}", ConfigurationManager.AppSettings["RemoteBasePort"])%>,<%= string.Format("RemoteBaseServiceName={0}", ConfigurationManager.AppSettings["RemoteBaseServiceName"])%>" />
|
Next, modify your "Application_Startup" method found in the App.xaml.cs. In this method, you have access to the initParams you created in the default.aspx through the "StartupEventArgs e". For development purposes, I added an "if" statement which will ignore the appSettings in the web.config if your "remoteBaseURL" property in the application's app.config is set to http://localhost - http://localhost so that Visual Studio will run the app under Cassini.
private void Application_Startup(object sender, StartupEventArgs e) {
var config = IdeaBlade.Core.IdeaBladeConfig.Instance;
var serverInfo = config.ObjectServer;
if (serverInfo.RemoteBaseUrl != "http://localhost")
{
serverInfo.RemoteBaseUrl = e.InitParams[ "RemoteBaseURL"];
serverInfo.ServerPort = int.Parse(e.InitParams["RemoteBasePort"]);
serverInfo.ServiceName = e.InitParams[ "RemoteBaseServiceName"];
}
this.RootVisual = new Page();
}
|
|