我想将在Global.asax中定义的ArrayList公开给所有会话。这里是一些来自Global.asax和Default.aspx的代码:global.asax问题 - 为ASP.NET中的所有新会话授予ArrayList
public class Global : System.Web.HttpApplication
{
public ArrayList userNameList = new ArrayList();
protected void Application_Start(object sender, EventArgs e)
{
}
protected void Session_Start(object sender, EventArgs e)
{
}
}
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Global global = new Global();
User user = new User();
user.username = TextBox1.Text;
global.userNameList.Add(user);
if (global.userNameList.Count != 0)
{
foreach (User u in global.userNameList)
{
ListBox1.Items.Add(String.Format(u.username));
}
}
}
}
请告诉我我做错了什么。谢谢:)
欢迎来到SO,Krystian。欣赏代码示例。如果你描述了你所看到的问题,你可能会得到更多的帮助。 – Rap