当前位置:编程学习 > C#/ASP.NET >>

统计访问次数出错为什么


ApplicationCount.aspx

<% @ Page Language="C#" %>
<Script Language="C#" Runat="Server">
public void Page_Load(Object src,EventArgs e)
{
Application.Lock();
Application["User_Count"]=(Int32)Application["User_Count"]+1;
Application.UnLock();
count.Text = Application["User_Count"].ToString();
}
</script>
<html>
<head>
<title></title>
</head>
<body>
<b>演示Application</b>
<form runat="server">
当前的计数为:<asp:Label id="count" ForeColor="red" runat="server" />
</form>
</body>
</html>

global.asax

<Script Language="C#" Runat="Server">
public void Application_Start()
{
        Application["User_Count"]=0;
}
</Script>



错误:
未将对象引用设置到对象的实例。 
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 

异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。

源错误: 


行 4:  {
行 5:   Application.Lock();
行 6:   Application["User"]=(Int32)Application["User"]+1;
行 7:   Application.UnLock();
行 8:   count.Text = Application["User"].ToString();
 

源文件: c:\Inetpub\wwwroot\net\ApplicationCount.aspx    行: 6 

--------------------编程问答-------------------- 行   4:     { 
行   5:     Application.Lock(); 
行   6:     Application[ "User_Count  "]=(Int32)Application[ "User_Count  "]+1; 
行   7:     Application.UnLock(); 
行   8:     count.Text   =   Application[ "User_Count  "].ToString(); 
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,