globalization

Discussion in 'ASP .Net' started by Daves, Mar 15, 2005.

  1. Daves

    Daves Guest

    still trying to set variables for use in all sub-pages...

    thought I'd found the solution with global.ascx:
    Application("connstring") = "...";
    Session("UserID") = 0;

    well it turns out the application and session objects are not pure system
    int/string type of objects so that each time I access them I have to use a
    cast eg
    if ((int) Session("UserID") >0) ...

    I think this is not a good way so how oh how can I just add constants to the
    global class and then
    if (global.UserID >0) ...

    ???
     
    Daves, Mar 15, 2005
    #1
    1. Advertising

  2. Daves

    Daves Guest

    hmm sorry I've learned that "globalization" refers to something else than
    using variables set "globally" in global.ascx

    still... please can someone help me on this so easy thing: to set a static
    variable in global.ascx to use in all sub-pages?!

    "Daves" <> wrote in message
    news:...
    > still trying to set variables for use in all sub-pages...
    >
    > thought I'd found the solution with global.ascx:
    > Application("connstring") = "...";
    > Session("UserID") = 0;
    >
    > well it turns out the application and session objects are not pure system
    > int/string type of objects so that each time I access them I have to use a
    > cast eg
    > if ((int) Session("UserID") >0) ...
    >
    > I think this is not a good way so how oh how can I just add constants to
    > the global class and then
    > if (global.UserID >0) ...
    >
    > ???
    >
     
    Daves, Mar 15, 2005
    #2
    1. Advertising

  3. Daves

    Guest

    Variables/Classes are stored as "Objects" in your Session.
    so you should do something like this
    if (Session("UserID") is null) then
    Session("UserID") = 100
    Else
    ' session is already set to use it you have to cast it to an int
    dim p as int = (Int) Session("UserID")
    End if
    I "think" this code will work. Basically you need to check to see if
    the object exists. If it does not exist you need to initialize it to a
    value.


    If this does not solve your problem then try to rephrase your question
    and provide more details.
    Remember that Sesion Variables are specific to a user's web session
    where as application are specific to the whole website.
    Information about a user would be stored in a session. rmembering that
    when the user is idle for more hten 20 minutes this information is
    lost.
    Information about the whole site woudl be stored in your Application.
    This information is lost if the application is restarted for any reason
    or the web server is restarted.
     
    , Mar 15, 2005
    #3
  4. Daves

    Daves Guest

    thx, this is true - it works by casting and I do watch out not having them
    set as null.
    But I still want to access the variables just as simple class (static)
    properties; they are easier to access (global.UserId rather than (int)
    Session("UserID")) and as I understand the case they are easier load on the
    server

    "" <> wrote in message
    news:...
    > Variables/Classes are stored as "Objects" in your Session.
    > so you should do something like this
    > if (Session("UserID") is null) then
    > Session("UserID") = 100
    > Else
    > ' session is already set to use it you have to cast it to an int
    > dim p as int = (Int) Session("UserID")
    > End if
    > I "think" this code will work. Basically you need to check to see if
    > the object exists. If it does not exist you need to initialize it to a
    > value.
    >
    >
    > If this does not solve your problem then try to rephrase your question
    > and provide more details.
    > Remember that Sesion Variables are specific to a user's web session
    > where as application are specific to the whole website.
    > Information about a user would be stored in a session. rmembering that
    > when the user is idle for more hten 20 minutes this information is
    > lost.
    > Information about the whole site woudl be stored in your Application.
    > This information is lost if the application is restarted for any reason
    > or the web server is restarted.
    >
     
    Daves, Mar 15, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dejan Vesic
    Replies:
    1
    Views:
    674
    Chee Seong Ong
    Jul 3, 2003
  2. Xavier MT

    Problem with globalization

    Xavier MT, Aug 4, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    1,532
    Jerry III
    Aug 5, 2003
  3. FM

    Globalization problem

    FM, Oct 21, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    4,838
    Nicole Calinoiu
    Oct 21, 2003
  4. Michael
    Replies:
    1
    Views:
    464
    Michael Beckmann
    Nov 3, 2003
  5. Niels Behrensen

    Globalization and satellite assemblies

    Niels Behrensen, Nov 3, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    356
    Niels Behrensen
    Nov 3, 2003
Loading...

Share This Page