Wrox Programmer Forums
|
ASP.NET 3.5 Professionals If you are an experienced ASP.NET programmer, this is the forum for your 3.5 questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Professionals section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 15th, 2009, 04:53 AM
Friend of Wrox
 
Join Date: Jan 2006
Posts: 180
Thanks: 1
Thanked 1 Time in 1 Post
Send a message via ICQ to dpkbahuguna Send a message via MSN to dpkbahuguna Send a message via Yahoo to dpkbahuguna
Default Live Users

hello friend,
I am maiking a little site...in which I am adding a conecpt to see how many users are online for only administrator user. It is working fine If i am running it at my Computer but when I am uploading my site then it is working only 2 or 3 times after that my Application oject gets Null.
I am doing this so to achieve this concept:
--------------------------------------------------------------------------

Global.asax
<%@ Application Language="C#" %>
<%@ Import Namespace="System.Collections.Generic" %>

<script runat="server">
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
List<string> UserOnLine = new List<string>();
Application["UserOnLine"] = UserOnLine;

}
</script>
--------------------------------------------------------------------------
MyLoginPage.aspx
//here as anyone login I am adding it to Application["UserOnline"]

if (PwdChk == Login1.Password)
{
Login1.DestinationPageUrl = "~/UserHome.aspx";
e.Authenticated = true;
//Adding this user to the Live users' list
Application.Lock();
List<string> UserOnLine = new List<string>();
UserOnLine = (List<string>)Application["UserOnLine"];
UserOnLine.Add(Login1.UserName);
Application["UserOnLine"] = UserOnLine;
Application.UnLock();
}
----------------------------------------------------------------------------
Administration.aspx
//here I am showing the online users by clicking the linkbutton.

protected void lnkbt_OnLineUsers_Click(object sender, EventArgs e)
{
try
{
//Listing for Online Users.
List<string> UsersOnline = new List<string>();
UsersOnline = (List<string>)Application["UserOnLine"];
GV_UserOnLine.DataSource = (List<string>)Application["UserOnLine"];
GV_UserOnLine.DataBind();

if (UsersOnline.Count == 0)
lbl_FileContents.Text = "There are no Online user found.";
}
catch (Exception Ex)
{
BLL BLOBJ = new BLL();
BLOBJ.WriteErrorLog(Ex.Message);
Response.Redirect("ServerBusyError.htm");
}

}
=============================================


help me here friends..it is all I am doing to show...


thanks !!!!
__________________
DPK..

Last edited by dpkbahuguna; July 16th, 2009 at 05:29 AM..
 
Old July 16th, 2009, 05:34 AM
Friend of Wrox
 
Join Date: Jan 2006
Posts: 180
Thanks: 1
Thanked 1 Time in 1 Post
Send a message via ICQ to dpkbahuguna Send a message via MSN to dpkbahuguna Send a message via Yahoo to dpkbahuguna
Default Live Users

anyone who cud tell wht is fault in this code
__________________
DPK..
 
Old July 16th, 2009, 06:09 PM
Lee Dumond's Avatar
Wrox Author
 
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

There are faults with this code.

The main one is that in a hosted situation, the app pool can recycle at any time, and there is no way you can control that. Another is that you are adding users as they log in, but you are doing nothing when users log out. Of course, many users never actually log out, so there's no reliable way to implement that functionality anyway.

Besides, the Membership system already tracks this information, so why reinvent the wheel? This should do the trick nicely.

Code:
protected void btnOnlineUsers_Click(object sender, EventArgs e)
{
   IEnumerable<MembershipUser> users = Membership.GetAllUsers().Cast<MembershipUser>();
   var onlineUsers = users.Where(u => u.IsOnline);
 
   gvUsersOnline.DataSource = onlineUsers;
   gvUsersOnline.DataBind();
}
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}
The Following User Says Thank You to Lee Dumond For This Useful Post:
dpkbahuguna (July 17th, 2009)
 
Old July 17th, 2009, 01:15 AM
Friend of Wrox
 
Join Date: Jan 2006
Posts: 180
Thanks: 1
Thanked 1 Time in 1 Post
Send a message via ICQ to dpkbahuguna Send a message via MSN to dpkbahuguna Send a message via Yahoo to dpkbahuguna
Default Live users

thanks Lee to reply...
IEnumerable<MembershipUser> OLineUsers = Membership.GetAllUsers().Cast<MembershipUser>();
var OLUser = OLineUsers.Where(OLineUsers => OLineUsers.IsOnline);
GV_UserOnLine.DataSource = OLineUsers;
GV_UserOnLine.DataBind();

here I am getting the error in OLineUsers object which I have written in Red Forecolor, I did not get in your code that what is the 'u' object there so I used OlineUsers in place of that... Error is :

Error 2 A local variable named 'OLineUsers' cannot be declared in this scope because it would give a different meaning to 'OLineUsers', which is already used in a 'parent or current' scope to denote something else.

I did not used that object anywhere.
__________________
DPK..
 
Old July 17th, 2009, 09:08 AM
Lee Dumond's Avatar
Wrox Author
 
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

Yes, this is because OLineUsers is being used in the first line, so you cannot use it in again in the lambda expression.

Also, you are binding the GridView to the wrong collection at the end.

Try this:

Code:
   IEnumerable<MembershipUser> users = Membership.GetAllUsers().Cast<MembershipUser>();
   var onlineUsers = users.Where(u => u.IsOnline);
 
   GV_UserOnline.DataSource = onlineUsers;
   GV_UserOnline.DataBind();
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}
 
Old July 18th, 2009, 06:37 AM
Friend of Wrox
 
Join Date: Jan 2006
Posts: 180
Thanks: 1
Thanked 1 Time in 1 Post
Send a message via ICQ to dpkbahuguna Send a message via MSN to dpkbahuguna Send a message via Yahoo to dpkbahuguna
Default Live User

thanks lee to reply I used ur code it is running but OnLineUesrs is empty it does not have any user list..one thing I have to ask that how:

IEnumerable<MembershipUser> users = Membership.GetAllUsers().Cast<MembershipUser>();
var onlineUsers = users.Where(u => u.IsOnline);

this all code will get the user list..i mean from where? and as u said before so Application object is not reliable then we cant take any use of Application object when our app pool can recycle any time..? pls make me understnad..
__________________
DPK..





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to get Live data from a web_page Hoang Excel VBA 2 April 10th, 2008 03:32 AM
Live Search? Ashleek007 Ajax 1 June 4th, 2007 01:25 AM
LIVE RADIO theokrtz Classic ASP Professional 1 August 24th, 2004 07:36 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.