ASP.NET - online

Asked By Dvorkin
13-Sep-11 02:00 PM
 i want to show how many users are online on my website or using my website at label control ....
  smr replied to Dvorkin
13-Sep-11 02:10 PM
hi

To show number of online visitors/users on your ASPX page you can use this code:
 
    Visitors online: <%= Application["OnlineUsers"].ToString() %>

  smr replied to Dvorkin
13-Sep-11 02:12 PM
hi

There are many ways to count number of active visitors on your ASP.NET website.
They differ in technique and accuracy.


Step 1:
 
  - first we need to add these lines to our global.asax file
    (if your website do not have it, create it by right-clicking on website in solution explorer,
     and choosing Add New Item > Global Application Class option)
 
  void Application_Start(object sender, EventArgs e)
 
  {
 
    // Code that runs on application startup
 
    Application["OnlineUsers"] = 0;
 
  }
 
  
 
  void Session_Start(object sender, EventArgs e)
 
  {
 
    // Code that runs when a new session is started
 
    Application.Lock();
 
    Application["OnlineUsers"] = (int)Application["OnlineUsers"] + 1;
 
    Application.UnLock();
 
  }
 
  
 
  void Session_End(object sender, EventArgs e)
 
  {
 
    // Code that runs when a session ends.
 
    // Note: The Session_End event is raised only when the sessionstate mode
 
    // is set to InProc in the Web.config file. If session mode is set to StateServer
 
    // or SQLServer, the event is not raised.
 
    Application.Lock();
 
    Application["OnlineUsers"] = (int)Application["OnlineUsers"] - 1;
 
    Application.UnLock();
 
  }

Step 2:
  In order for this to work correctly we need to enable sessionstate and configure its mode to InProc value (in our web.config file):
 
    <system.web>
 
    <sessionState mode="InProc" cookieless="false" timeout="20" />
 
    </system.web>
 
 
In-process mode stores session state values and variables in memory on the local Web server.
It is the only mode that supports the Session_OnEnd event that we used previously.


refer link
http://aspdotnetfaq.com/Faq/How-to-show-number-of-online-users-visitors-for-ASP-NET-website.aspx
  dipa ahuja replied to Dvorkin
13-Sep-11 02:46 PM
Untitled document
► Add a Global.asax file in your website >> Add New Item >>Global Application Class and write this code in it.
 
public static int count = 0;
 
void Application_Start(object sender, EventArgs e)
  {
   
Application["myCount"] = count;
 }

 
void Session_Start(object sender, EventArgs e)
  {
   count =
Convert.ToInt32(Application["myCount"]);
   
Application["myCount"] = count + 1;
 }
 
Now every time when visitor open your site the variable count will be increased by one.
 
► To Get the total at you home page you can write it as:
 
int a;
a = Convert.ToInt32(Application["myCount"]);
 
  Devil Scorpio replied to Dvorkin
13-Sep-11 03:23 PM
Hi Dvorkin,

There are many ways to count number of active visitors on your ASP.NET website.
They differ in technique and accuracy.

here is the simplest approach that delivers acceptable accuracy when configured optimally:

Step 1:

    - first we need to add these lines to our global.asax file
    (if your website do not have it, create it by right-clicking on website in solution explorer,
     and choosing Add New Item > Global Application Class option)

    void Application_Start(object sender, EventArgs e)
    {
        // Code that runs on application startup
        Application["OnlineUsers"] = 0;
    }
 
    void Session_Start(object sender, EventArgs e)
    {
        // Code that runs when a new session is started
        Application.Lock();
        Application["OnlineUsers"] = (int)Application["OnlineUsers"] + 1;
        Application.UnLock();
    }
 
    void Session_End(object sender, EventArgs e)
    {
        // Code that runs when a session ends. 
        // Note: The Session_End event is raised only when the sessionstate mode
        // is set to InProc in the Web.config file. If session mode is set to StateServer 
        // or SQLServer, the event is not raised.
        Application.Lock();
        Application["OnlineUsers"] = (int)Application["OnlineUsers"] - 1;
        Application.UnLock();
    }

This will allow us that whenever some distant web visitor opens our website in his browser,
and new session is created for him, our  "OnlineUsers" variable in the global HttpApplicationState class instance
is increased.

Also when user closes his browser or does not click on any links in our website, session expires,
and our "OnlineUsers" global variable is decreased.

To know more about ApplicationState and HttpApplicationState class visit this MSDN link:
http://msdn2.microsoft.com/en-us/library/system.web.httpapplicationstate%28VS.80%29.aspx

NOTE:
we are using Application.Lock and Application.Unlock methods to prevent multiple threads
from changing this variable at the same time.

By calling Application.Lock we are receiving exclusive right to change the values in Application state.
But we must not forget to call Application.Unlock() afterwards.

Step 2:
  In order for this to work correctly we need to enable sessionstate and configure its mode to InProc value (in our web.config file):

        <system.web>
        <sessionState mode="InProc" cookieless="false" timeout="20" />
        </system.web>

In-process mode stores session state values and variables in memory on the local Web server.
It is the only mode that supports the Session_OnEnd event that we used previously.

Timeout value (in minutes, not in seconds) configures how long our sessions are kept 'alive' - in other words
here we set how long our users can be inactive before considered Offline.

In this example timeout is set to 20 minutes, so while our visitors click on some links in our website at least once
in a 20 minutes, they are considered online.
If they do not open any pages on our website longer than 20 minutes, they are considered Offline, and their session
is destroyed, so our online visitor counter is decreased by 1.
(You can experiment with lower or higher values of Timeout settings to see what is the best for your website).

Ok, so now we are done with configuration steps, let us see how to use this:

To show number of online visitors/users on your ASPX page you can use this code:

        Visitors online: <%= Application["OnlineUsers"].ToString() %>

Next you could put this code snippet in you UserControl, or inside Asp.Net AJAX UpdatePanel control, and
use Timer to refresh it in regular intervals without refreshing the whole page,
  Devil Scorpio replied to Dvorkin
13-Sep-11 03:25 PM
Hi,

Just call this variable where you want to display no of users like if you have label some where then just

label1.Text=Application("user_sessions")


Refer this website link for the same

 

http://blog.dreamlabsolutions.com/post/2009/07/13/ASPNET-Membership-Show-list-of-users-online.aspx 

  Reena Jain replied to Dvorkin
13-Sep-11 03:37 PM
hi,

If you use the built-in ASP.NET membership provider, then there's the ever-so-handy http://msdn.microsoft.com/en-us/library/system.web.security.membership.getnumberofusersonline%28v=VS.100%29.aspx method. here is the eg for you

   
ASP.Net » Login Security » Membership  
   
Displaying the number of users online
 
<%@ Page Language="C#" %>
 
<script runat="server">
   protected void Page_Load(object sender, EventArgs e)
   {
  Label1.Text = Membership.GetNumberOfUsersOnline().ToString();
   }
</script>
 
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
  <title>Login or Logout</title>
</head>
<body>
  <form id="form1" runat="server">
  <asp:LoginStatus ID="LoginStatus1" Runat="server" />
  <p><asp:LoginName ID="LoginName1"
        Runat="server"
        Font-Bold="True"
        Font-Size="XX-Large" /></p>
  <p>There are <asp:Label ID="Label1" Runat="server" Text="0" />
     users online.</p>
  </form>
</body>
</html>

hope this will help you
  Riley K replied to Dvorkin
13-Sep-11 09:43 PM
You have to be more clear like what kind of Authntication are you using either ASP.Net Membership roles or
Normal Authentication using ADO.Net

IN Normal

In your db where you are storing the User Info you can have a column 'online' which could be a bit value and would be true if User is online and false when user is offline.

 

Set this value to true whenever user logs in.

 

Then You can easily get which users are online at any time. ('Select * from tbl_Users where online=true)

 Using Membership Roles

protected void Page_Load(object sender, EventArgs e)
  {
    MembershipUserCollection OnlineUsers = new MembershipUserCollection();
    MembershipUserCollection AllUsers = new MembershipUserCollection();
    AllUsers = Membership.GetAllUsers();
 
    foreach (MembershipUser user in AllUsers)
    {
      if (user.IsOnline)
      {
        OnlineUsers.Add(user);
 
      }
    }
    int OnlineUserCount = OnlineUsers.Count;
 
    lblSessionCount.Text = OnlineUserCount.ToString();
 
    OnlineUserList.DataSource = OnlineUsers;
    OnlineUserList.DataBind();
  }

Cheers


  James H replied to Dvorkin
14-Sep-11 12:00 AM
Hi you can get the Online Visitor Count like this
In Web Config

Step one - Add Reference

After downloading the attachment, you should add a reference to the project. If you know how to add references, please skip this step.

To add the reference, right click on your solution and select "Add Reference" from the menu. Then select the "OnlineActiveUsers.dll" file. Now the reference is added to the solution.

Step two - Change configuration

Open the "Web.config" file from your project (if this file is absent, right click on your project and from "Add new item", select "Web configuration file"). Then, add this code to the "web.config" file.


<httpModules>
  <add name="OnlineActiveUsers"
     type="OnlineActiveUsers.OnlineUsersModule"/>
</httpModules>

Note that this code should be placed between the "system.web" tags.

Step three - Add some code to global.asax

Open the "global.asax" file in your project (if this file is absent, right click on your project and from "Add new item", select "Global Application Class"). In the "session_end" event, add this code:

If the project is C#, the result should be like this:

void Session_End(object sender, EventArgs e)
{
  OnlineActiveUsers.OnlineUsersInstance.OnlineUsers.UpdateForUserLeave();
}

Hope this will help you :-)


Create New Account
help
alot var Hi What are Master Pages in ASP.NET? or What is a Master Page? ASP.NET master pages allow you to create a consistent layout for the pages in your application. A single master page defines the look and feel and standard behavior that you want for all of the you want to display. When users request the content pages, they merge with the master page to produce output that combines the layout of the master page with the content from the content page. What are the 2 important parts of a master page? The following are the 2 important parts of a master page 1. The Master Page itself 2. One or more Content Pages Can Master Pages be nested? Yes, Master Pages
Page Directive? What is the purpose of page directive in aspx page? Directive Syntax Directives are instructions used to specify settings (related to how a page should render and processed) used by the page and user control compilers when they process ASP.NET Web Forms page (.aspx) and user control (.ascx) files. These are the essential part of every ASP.NET Page or Control. Directives can be located anywhere in an .aspx or .ascx file, but the values, same as any HTML tag) that are specific to that directive. Special Note: The @ Page directive can be used only in .aspx files, and the @ Control directive can be used
Remove(e.TabPage); } _cache.Add(e.TabPage); } } private void button1_Click(object sender, EventArgs e) { TabPage page = new TabPage("TabPage" + pageNumber.ToString()); AddControlsToTabPage(page); this.tabControl1.TabPages.Add(page); pageNumber++; this.tabControl1.SelectedTab = page; } private void AddControlsToTabPage(TabPage page) { page.Controls.Add(this.tab1CheckBox1); page.Controls.Add(this.tabCheckBox2 page.Controls.Add(this.tabCheckBox3); page.Controls.Add(this.tabCheckBox4); page.Controls.Add(this.tabCheckBox5); page
renders the same css differently. Very odd. Sir also some other features : in our profile page we are not able to see the symbol of answer unchecked, checked , ignored, 3* , 1 just missed that feature. Sir, now most of things are working fine as expected ! Profile page , My Post Page etc working good ! site looks great ! Sir one thing i notice . . Every posts has the asp-net / 17 / 10371909 / gridview-sorting-using-jquery.aspx Navigation menu missing in forum merit page http: / / www.eggheadcafe.com / forummerit.aspx Regards Hi Robbe, I suggest you that, if you hi. . previously there is dropdownlist in which we used to select number of posts per page . . . but in the New site it is missing. . . . hi. . . check out the belowlines 2 Replies each Answer posted Hi Robbe, After giving replay for the question and submitting the button, page is showing the top of the page. My suggestion is if the page shows the answer which we have replied wiil be better. hi. . in the below link