asp.net c#代码
<%@ Page Language="C#" Debug="true" ContentType="text/html" ResponseEncoding="gb2312" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<form runat="server"><script runat="server">
protected void Page_Load(Object sender, EventArgs e)
{ Application("count")="1";
Application.Lock();
Application.Set("count",(int)Application["count"]+1);
this.Label1.Text=
"你是本站的第"+Application["count"]+"位访问者";
}
</script>
<asp:Label ID="Label1" runat="server" />
</form>
</body>
</html>
编译器错误信息: CS0118: “System.Web.UI.Page.Application”是“属性”,但此处被当做“方法”来使用
这是课本的例子也不正确,如何修改???
<%@ Application Language="C#" %>
<script runat="server">
private System.IO.StreamWriter streamwrite;
private System.IO.StreamReader streamread;
private System.IO.FileStream file;
void Application_Start(object sender, EventArgs e)
{
// 在应用程序启动时运行的代码
Application["CurrentGuests"] = 0;
file = System.IO.File.Open(Server.MapPath("counts.text"), System.IO.FileMode.OpenOrCreate);
streamread = new System.IO.StreamReader(file);
Application["AllGuests"] = Convert.ToInt32(streamread.ReadLine());
streamread.Close();
}
void Application_End(object sender, EventArgs e)
{
// 在应用程序关闭时运行的代码
}
void Application_Error(object sender, EventArgs e)
{
// 在出现未处理的错误时运行的代码
}
void Session_Start(object sender, EventArgs e)
{
// 在新会话启动时运行的代码
Application.Lock();
Application["CurrentGuests"] = (int)Application["CurrentGuests"] + 1;
Application["AllGuests"] = (int)Application["AllGuests"] + 1;//访问网站的总用户数
file = System.IO.File.Open(Server.MapPath("counts.text"), System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.ReadWrite);
streamwrite = new System.IO.StreamWriter(file);
streamwrite.WriteLine(Application["AllGuests"].ToString());
streamwrite.Close();
Application.UnLock();
}
void Session_End(object sender, EventArgs e)
{
// 在会话结束时运行的代码。
// 注意: 只有在 Web.config 文件中的 sessionstate 模式设置为
// InProc 时,才会引发 Session_End 事件。如果会话模式设置为 StateServer
// 或 SQLServer,则不会引发该事件。
Application.Lock();
Application["CurrentGuests"] = (int)Application["CurrentGuests"] - 1;
Application.UnLock();
}
</script>