今天我的朋友八爪问如何在SL里面读配置文件,以便配置WCF的EndPoint,我和他掰了半天,没找到Web.config,如果自己去写xml又不能保证安全,还好他提出从aspx里面传入。当时觉得这个想法有些勉强。呵呵!不过后来想想还是有道理的
通过InitParameters加入参数,用来向xaml里传入参数
<asp:Silverlight ID="Xaml1" runat="server" Source="~/ClientBin/RegisterClient.xap" InitParameters="url=http://127.0.0.1/reclient/c.aspx" Version="2.0" Width="100%" Height="100%" />
在app.xaml.cs里面加入代码
private void Application_Startup(object sender, StartupEventArgs e)
{
// Load the main control
string url = e.InitParams["url"];
this.RootVisual = new RegisterMain();
// this.RootVisual = new Test4();
}
为什么要这么做,因为sl只是一个插件,它的数据是来自外部传递,不应该让他自己去读web.config,因为web.config是为整个Web应用服务的,所以要实现 sl读取Web.config就需要从aspx里传入
1409

被折叠的 条评论
为什么被折叠?



