5

I am fairly new to web development. I am at the point of deployment (for testing). I have a few places (maybe 4 places) where I had to add a URI that was non-relative into the appliation. So now, at deployment, those need to be changed.

Is there a slick way of handling this? By slick I mean not manually going through the app and changing the URIs or a blanket find and replace (too risky). I only have 4 places to change now, but this could easily change and cause deployment issues.

I am using a Microsoft technology stack. Silverlight, ASP.NET, RIA, etc. Development is done in Visual Studio 2010.

I noticed that the web projects have a nifty transformation for the web.config...which is nice. Is there an equivalent mechanism for silverlight resources? Any other ways?

Any thoughts?

Mike S.
  • 402
  • 1
  • 3
  • 13

3 Answers3

1

One way is to pass parameters to the Silverlight application from the hosting web page.

<object ....>
... 
<param name="initParams" value="prm1=http://google.com,prm2=http://bing.com" />
...
</object>

And access from your Silverlight app (App.xaml.cs, Application_Startup method):

foreach (var item in e.Initparams)
{
  this.Resources.Add(item.Key, item.Value);
}

Access the parameters:

var prm1 = App.Current.Resources["prm1"].ToString();
Magnus Johansson
  • 28,010
  • 19
  • 106
  • 164
1

I just found this post on stack overflow concerning using MS's built in transformation mechanism for service references. But in reality...it's generic for any XML file. Which means I was able to apply the same concepts to my custom XML file that held some settings...and it worked brilliantly.

See Randoms solution. It isn't the selected solution but it is far better than anything else I have seen.

Community
  • 1
  • 1
Mike S.
  • 402
  • 1
  • 3
  • 13
0

It's not too pretty, but you can check for the DEBUG define (defined in debug mode builds by default):

#if (DEBUG)
    myUrl = "http://www.google.com";
#else
    myUrl = "http://www.bing.com";
#endif
toby
  • 885
  • 3
  • 10
  • 21