在类项目中读取asp.net中的web.config数据库链接
Class1.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ClassLibrary1
{
public class Class1
{
public string testconSQL()
{
string conSQL = System.Configuration.ConfigurationSettings.AppSettings["mySystem"].ToString();
return conSQL;
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ClassLibrary1
{
public class Class1
{
public string testconSQL()
{
string conSQL = System.Configuration.ConfigurationSettings.AppSettings["mySystem"].ToString();
return conSQL;
}
}
}
asp.net web.config
<appSettings>
<add key="mySystem" value="server=localhost;uid=sa;pwd=123;database=mySystemDataBase" />
</appSettings>
<add key="mySystem" value="server=localhost;uid=sa;pwd=123;database=mySystemDataBase" />
</appSettings>
Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ClassLibrary1;
namespace WebApplication1
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Class1 aa = new Class1();
Response.Write(aa.testconSQL());
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ClassLibrary1;
namespace WebApplication1
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Class1 aa = new Class1();
Response.Write(aa.testconSQL());
}
}
}