0

in global.asax:
i given this code

public static int count = 0; 
    void Application_Start(object sender, EventArgs e) 
    {
        // Code that runs on application startup
        Application["myCount"] = count;
    }
     void Session_Start(object sender, EventArgs e) 
    {
        // Code that runs when a new session is started
        //count = Convert.ToInt32(Application["myCount"]);
        count = Convert.ToInt32(Application["myCount"]);
        Application["myCount"] = count + 1;
    }

in aspx page i given this thing

protected void Page_Load(object sender, EventArgs e)
    {
        Application.Lock();
        if(Application["HitCount"]!=null)
         {
            Application["HitCount"]=(int)Application["HitCount"]+1;
         }
        else
         {
             Application["HitCount"] =1;
         }
         Application.UnLock();
        lblInfo.Text="The page has been accessed ("+Application["HitCount"].ToString()+") times";

but the problem here is it is counting up to certain time that means up to 1hr and again incrementing starts from 1 whats the problem and help me to overcome this one.

Edited by __avd: Added [code] tags. For easy readability, always wrap programming code within posts in [code] (code blocks).

2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by __avd
0

in global.asax:
i given this code

public static int count = 0; 
    void Application_Start(object sender, EventArgs e) 
    {
        // Code that runs on application startup
        Application["myCount"] = count;
    }
     void Session_Start(object sender, EventArgs e) 
    {
        // Code that runs when a new session is started
        //count = Convert.ToInt32(Application["myCount"]);
        count = Convert.ToInt32(Application["myCount"]);
        Application["myCount"] = count + 1;
    }

in aspx page i given this thing

protected void Page_Load(object sender, EventArgs e)
    {
        Application.Lock();
        if(Application["HitCount"]!=null)
         {
            Application["HitCount"]=(int)Application["HitCount"]+1;
         }
        else
         {
             Application["HitCount"] =1;
         }
         Application.UnLock();
        lblInfo.Text="The page has been accessed ("+Application["HitCount"].ToString()+") times";

but the problem here is it is counting up to certain time that means up to 1hr and again incrementing starts from 1 whats the problem and help me to overcome this one.

:-O
Everything that you store in Application object is kept in memory until the application is closed by the last user connected.

0

sorry i cant get u r answer will you pls eloborate it.?
i am not that much expert in this topic pls eloborate the answer sir..

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.