Global.asax problem

Last post 05-12-2008 9:56 AM by Florida. 6 replies.

Sort Posts:

  • Global.asax problem

    05-09-2008, 4:47 PM
    • Loading...
    • Florida
    • Joined on 05-09-2008, 4:03 PM
    • Posts 4

    I am starting to learn web development using VWD 2008 express. Here is a simple situation in global.asax. I want to display a user count on my page and I am using this code:

    void Application_Start(object sender, EventArgs e)

    {

    Application.Add("userCount", 0);

    }

     

    void Session_Start(object sender, EventArgs e)

    {

    Application("userCount") += 1;

    }

    When I debug, I get this

    Error 1 The left-hand side of an assignment must be a variable, property or indexer 

    Error 2 Operator '+=' cannot be applied to operands of type 'object' and 'int' 
     

    Both errors are for the line of  code in the Session_Start event

    I have tried to see if there are any posts regarding this but did not see any. So any help is appreciated.

  • Re: Global.asax problem

    05-09-2008, 4:55 PM
    Answer
    • Loading...
    • joteke
    • Joined on 06-16-2002, 11:24 AM
    • Kyro, Finland
    • Posts 6,360
    • ASPInsiders
      Moderator
      TrustedFriends-MVPs

    This

    Application("userCount") += 1; 

    should be:

    Application.Lock()
    int cnt = (int)Application[
    "userCount"];
    Application[
    "userCount"] = cnt + 1;
    Application.UnLock();

     

    Thanks,

    Teemu Keiski
    Finland, EU
  • Re: Global.asax problem

    05-09-2008, 5:00 PM
    • Loading...
    • JZoerman
    • Joined on 08-24-2006, 6:27 AM
    • Posts 98

    public void Application_Start(object sender, EventArgs e)
    {
        Application("userCount") = 0;
    }

    public void Application_End(object sender, EventArgs e)
    {
    }

    public void Application_Error(object sender, EventArgs e)
    {
    }

    public void Session_Start(object sender, EventArgs e)
    {
        Application("userCount") += 1;
    }

    public void Session_End(object sender, EventArgs e)
    {
        Application("userCount") -= 1;
    }

  • Re: Global.asax problem

    05-10-2008, 12:08 PM
    • Loading...
    • Florida
    • Joined on 05-09-2008, 4:03 PM
    • Posts 4

    joteke, your solution worked. Thanks a bunch. 

    I understand your code but I was following a learning video that used this code: "Application("userCount") += 1; " and I wonder how it worked for them? Could it be a difference between VWD 2005 express and VWD 2008 express ?  I am using VWD 2008 express but the learning video is taught using VWD 2005 express. 

  • Re: Global.asax problem

    05-10-2008, 12:17 PM
    • Loading...
    • Florida
    • Joined on 05-09-2008, 4:03 PM
    • Posts 4

    JZoerman, your solution is what I tried in the first place and that is what gave me the errors.

    JZoerman:
    Application("userCount") += 1;
     gives errors in vwd 2008 express.

  • Re: Global.asax problem

    05-11-2008, 4:58 AM
    • Loading...
    • joteke
    • Joined on 06-16-2002, 11:24 AM
    • Kyro, Finland
    • Posts 6,360
    • ASPInsiders
      Moderator
      TrustedFriends-MVPs

    Florida:

    joteke, your solution worked. Thanks a bunch. 

    I understand your code but I was following a learning video that used this code: "Application("userCount") += 1; " and I wonder how it worked for them? Could it be a difference between VWD 2005 express and VWD 2008 express ?  I am using VWD 2008 express but the learning video is taught using VWD 2005 express. 

    I don't believe the approach in the video it works, since there are 2 errors in that approach.First was that in C# one uses [...]'s to indexing, VB.NET uses (...)'s. Second is that Application collections Item property (which you index to) is typed as object and accumulating integer to it doesn't make sense (e.g C# is strict about types). Again, that would work in VB (although IN VS2005 and 2008 syntax checking is stricter by default)

    Thanks,

    Teemu Keiski
    Finland, EU
  • Re: Global.asax problem

    05-12-2008, 9:56 AM
    • Loading...
    • Florida
    • Joined on 05-09-2008, 4:03 PM
    • Posts 4

    Ok cool, I gotcha.  I used C#, but the instructional video was using VB.  I like to try something a bit different rather than just blindly follow instructions from the video.  Now I learned a lot more than what was being taught on the video. Thanks to you sir.  You are the best.

Page 1 of 1 (7 items)