在同一解决方案中如何使用从web.config到app.config的连接字符串 [英] How to use the connection string from web.config into app.config in the same solution
问题描述
Hi Experts
我有一个相当研究型的问题,我在谷歌上搜索了很多,但是找不到任何解决方案.也许这里的任何人都可以对此有所了解.
在具有类库项目中的app.config和网站项目中的web.config的网站解决方案中,类库项目是否可以直接使用来自web.config的连接字符串?如果是,那么可能的解决方案是什么?
Hi Experts
I have a rather research type of question for which I googled a lot but could not find any solution. May be anybody here can throw a some light on this.
In a website solution with app.config in a class library project and web.config in website project, is it possible that the class library project can directly use the connection string from web.config ? If yes, then what are the probable solutions ?
推荐答案
没有任何直接的解决方案,但是您可以在Web应用程序中使用获取web.config连接字符串.
there isn''t any direct solution for this, but you can use a web service in your web application that get the web.config connection strings.
namespace test
{
/// <summary>
/// Summary description for WebService1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class WebService1 : System.Web.Services.WebService
{
[WebMethod]
public List<string> Conns()
{
var items = System.Configuration.ConfigurationManager.ConnectionStrings.Cast<string>().ToList();
return items;
}
}
}
此Web服务返回列表中的所有连接!
这是您的基础,请继续阅读在线资源以获取帮助,如果对此有疑问,请再次询问!
this web service return all connections in a list!
this is a base for you, go ahead and read online resources for help and if you have question about this ask again!
这篇关于在同一解决方案中如何使用从web.config到app.config的连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!