Re: Session Variables Disappearing

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Alvin Bruney [MVP] (vapor)
Date: 02/16/04


Date: Sun, 15 Feb 2004 22:16:02 -0600

you have custom controls on that page? custom controls cannot directly
access session, you need to first get a reference to the session object from
httpcontext.current.

If that still doesn't work, you will need to put code to display the session
variable in the page load and troubleshoot from there

if(Session["UserName"]!= null)
    Response.Write("<script>alert('" + Session["UserName"].ToString() +
"')</script>");

should display something

-- 
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/3he3b
"Paul Yanzick" <yanzickp@hotmail.com> wrote in message
news:-sudnUOIdbqWgq3dRVn2sg@giganews.com...
> Hello!
>
> The session state information in the web.config is as follows:
>
> <sessionState
>
> mode="InProc"
>
> stateConnectionString="tcpip=127.0.0.1:42424"
>
> sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes"
>
> cookieless="false"
>
> timeout="20"
>
> />
>
> There is no <pages> element in the Web.config.  I want to have the session
> variables be available to all of the pages in the project.
>
> Most of the variables that are in the session state are strings, so I use
> (string) to cast them.  For example, in the status bar user control, I
use:
> lblUserName.Text="Logged in using: " + Session["UserName"].ToString();
>
> lblSecurity.Text="Security Level: " +
> Authenticate.GetSecurityLevelText((int)Session["SecurityLevel"]);
>
> The first line accesses the session directly, and uses ToString() to get
the
> info.  The second line I am casting it to an integer to throw into the
> function.  The funny thing with these and the status bar is once it logs
on
> and takes you to the menu, all of the info is currect, however if I move
> past that, the first line produces 'Logged in using:' and that is it,
while
> the second line produces absolutely nothing.
>
> Thanks for your help!
>
> Paul
>
>
>
> "Milan Negovan" <santa@northpole.net> wrote in message
> news:TXSXb.10685$cE3.17376713@news4.srv.hcvlny.cv.net...
> > Hi Paul,
> >
> >
> > > I don't receive any errors, there just isn't anything that appears in
> these
> > > fields.  Each page has sessions enabled.  If you have any suggestions,
> > > PLEASE let me know!
> >
> > You mentioned each page had session enabled. Is there a chance the
> > session is disabled in web.config? What does your <sessionState> element
> > look like?
> >
> > Also, do you happen to have a <pages> element in web.config that
> > disables the session state for certain files?
> >
> > Also, how do you cast values you read from the Session object?
> >
> > -- 
> > Milan Negovan
> > www.AspNetResources.com
> > Essential recources for ASP.NET developers
>
>


Relevant Pages

  • Re: Session Variables Disappearing
    ... you have custom controls on that page? ... access session, you need to first get a reference to the session object from ... > Most of the variables that are in the session state are strings, ... how do you cast values you read from the Session object? ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: ASP.NET 2.0 Session_End Question
    ... If the page doesn't use session state, the user won't be identified and no Session object is associated with the request. ... Some web servers are set to recycle daily or even more often, but from the randomness it sounds more like it gets recycled because of some performance problem. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: About Session Object
    ... the session state will be managed ... If using cookies, the session state will be managed with cookies. ... > When is the session object created and by which class,httpruntime or ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Dataset in Session state
    ... Is it possible to release memory occupied by a Session object? ... Vik ... the dataset is saved in session state only once when it is empty. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Session Variables Disappearing
    ... Thanks for the suggestion! ... > you have custom controls on that page? ... > access session, you need to first get a reference to the session object ... > If that still doesn't work, you will need to put code to display the ...
    (microsoft.public.dotnet.languages.csharp)