这样写没有输出,错在哪里??
web.config 片段
<connectionStrings>
<add name= "ConnectionString " connectionString= "Data Source=250;Persist Security Info=True;User ID=chenyi;Password=123456;Unicode=True "
providerName= "System.Data.OracleClient " />
</connectionStrings>
PublicOracleCon.cs
public class PublicOracleCon
{
public readonly String OracleConnectionString = ConfigurationManager.AppSettings[ "ConnectionString "];
public PublicOracleCon()
{
}
public void printStr()
{
System.Console.WriteLine(OracleConnectionString);
}
}
<%@ Page Language= "C# " AutoEventWireup= "true " CodeFile= "Default.aspx.cs " Inherits= "_Default " %>
default.aspx
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<%@ import Namespace= "System.Data " %>
<html xmlns= "http://www.w3.org/1999/xhtml " >
<head runat= "server ">
<title> 无标题页 </title>
</head>
<body>
<% PublicOracleCon poc = new PublicOracleCon();
poc.printStr();
%>
</body>
</html>
没有输出,错在哪里??
------解决方案--------------------public void printStr()
{
System.Console.WriteLine(OracleConnectionString); //这个是控制台输出呢,
//web页面应该是Response.write(OracleConnectionString);
}
------解决方案--------------------楼主,你怎么还在用ASP的思维写代码?
PublicOracleCon poc = new PublicOracleCon();
poc.printStr();
放到
default.aspx.cs的Page_Load事件中