Silverlight读取webconfig配置文件

遇到程序代码调试时可以正常读取web.config数据库连接串
System.Configuration.ConfigurationManager.ConnectionStrings["PigeonConnectionString"].ToString()
但部署到IIS上,却数据库连接失败,经过写日志跟踪发现读取的连接串为$(ReplacableToken_PigeonConnectionString-Web.config Connection String_0)
   解决方法1
  需要修改项目文件,注意是项目文件(即:D:\VS2010Pro\Pigeon.Web\Pigeon.Web.csproj 
在PropertyGroup里添加如下属性:
<AutoParameterizationWebConfigConnectionStrings>False</AutoParameterizationWebConfigConnectionStrings>
这样就会正常生成自定义的连接串
以下是截取的片段
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <AutoParameterizationWebConfigConnectionStrings>False</AutoParameterizationWebConfigConnectionStrings>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>

 

 

另外一种Silverlight读取网站项目中的Web.config数据库连接串的方法(VS2010)

添加一个Silverlight项目,会生成两个工程,(一个Silvelight项目,一个网站项目)

  1. 在网站项目的PA_QCReportTestPage.html和PA_QCReportTestPage.aspx中加入红色字体的内容

    <form id="form1" runat="server" style="height:100%">
    <div id="silverlightControlHost">
        <object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
    <param name="source" value="ClientBin/PA_QCReport.xap"/>
    <param name="onError" value="onSilverlightError" />
    <param name="background" value="white" />
    <param name="minRuntimeVersion" value="4.0.50826.0" />
    <param name="autoUpgrade" value="true" />
          <param name="InitParams" value='WcfServiceAddress=<%= System.Configuration.ConfigurationManager.AppSettings["WcfServiceAddress"] %>' />
    <a href="
http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.50826.0" style="text-decoration:none">
      <img src="
http://go.microsoft.com/fwlink/?LinkId=161376" alt="获取 Microsoft Silverlight" style="border-style:none"/>
    </a>
     </object><iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe></div>
    </form>
 
2.在Silverlight项目的App.xaml.cs中加入红色字体的内容

        private void Application_Startup(object sender, StartupEventArgs e)
        {
            var slServicePath = e.InitParams["WcfServiceAddress"];
            //将读取到的WCF地址保存到资源中。
            Application.Current.Resources.Add("WcfServiceAddress", slServicePath);
            this.RootVisual = new MainPage();
        }

          //调用方法

                              servicePicture.Endpoint.Address =
                        new System.ServiceModel.EndpointAddress(Application.Current.Resources["WcfServiceAddress"] + "/wcfMain.svc");

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值