Silverlight读取webconfig配置文件
2012-07-17 09:50
169 查看
遇到程序代码调试时可以正常读取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");
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");
相关文章推荐
- Silverlight读取Web.config配置文件(转)
- C# 读取webconfig配置文件Appseting key值的方法
- Silverlight 读取配置文件
- Silverlight读取Web.config配置文件
- Silverlight读取Web.config配置文件
- Silverlight读取Web.config配置文件
- PropertyPlaceholderConfigurer读取配置文件
- 读取资源(配置)文件的三种方式
- Java程序中的配置文件的存放和读取
- 读取到配置文件的C语言的接口实现
- IIS7虚拟目录出现HTTP错误500.19(由于权限不足而无法读取配置文件)
- Java读取src目录下的properties配置文件
- Spring-boot中读取config配置文件的两种方式
- java读取配置文件里的信息
- vs2005读取配置文件错误System.Configuration.ConfigurationSettings.AppSettings”已过时
- Mysql配置文件读取顺序
- java中读取properties配置文件
- 读取配置文件的内容 SAXReader Document
- 也许可以通过这种方式读取配置文件
- 启动dubbo provider无法读取spring 配置文件