session expires after logged in

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rahemeen
    New Member
    • Sep 2007
    • 11

    session expires after logged in

    as i developed a website using asp.net 2 vs2005 with database sqlserver and my website was running fine few days back but now i am getting a problem. i.e
    user is logged in and browsed a page which page is only logged in users can browse and when he runs server side script on that page immediately session expires and user redirected to login page. what causing page to redirect to login page. can anybody explain it and solve my problem.

    thanking you in advance.
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Is your SQL server handling the session state?
    I'm not sure how that sort of thing is handled.

    These are for regular session state handling but may still apply:
    Are you callin Session.Abandon () anywhere?
    Has the session timeout happened?
    Does the user have restricted cookie/security issues (like possibly just did a windows update and new security things were enacted)?

    Are any errors occuring in your program?
    If you do a build(and a publish if it's remotely hosted) your sessions will expire.

    Comment

    • rahemeen
      New Member
      • Sep 2007
      • 11

      #3
      thanks dear plater. i am not that expert so i have no idea about whether sql server handling session timeout or not. and s iam calling session.abondon () in a link button labled 'sign out' on the same page.
      and if user updated and new security restrictions applying then this problem i checked on two different pcs. and mean my page is online and i checked from two different areas. but the same problem

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        Well I would double-check the IIS settings to make sure:
        Your "Session state mode" is set to "InProc"
        Your "Cookieless mode" is set to "UseCookies "
        and your "Session timeout" is set to asuffeciently long enough time "20"(minute s)

        Then check to make sure no errors are being thrown that would be causeing your session to expire.

        Comment

        • rahemeen
          New Member
          • Sep 2007
          • 11

          #5
          i check all settings are fine and the same coding few days back was working fine but now it is giving this problem. in web.config file i am using windows authentication mode. and just loggin check up using database and session variables. below see web.config file (plz reply if any changes required)
          [code=xml]
          <?xml version="1.0"?>
          <!--
          Note: As an alternative to hand editing this file you can use the
          web admin tool to configure settings for your application. Use
          the Website->Asp.Net Configuration option in Visual Studio.
          A full list of settings and comments can be found in
          machine.config. comments usually located in
          \Windows\Micros oft.Net\Framewo rk\v2.x\Config
          -->
          <configuratio n>
          <appSettings>
          <add key="CMSConnect ionString"
          value="server=( localhost);UID= sa;PWD=111;DATA BASE=netdb;" />
          </appSettings>
          <connectionStri ngs/>
          <system.web>
          <!--
          Set compilation debug="true" to insert debugging
          symbols into the compiled page. Because this
          affects performance, set this value to true only
          during development.

          Visual Basic options:
          Set strict="true" to disallow all data type conversions
          where data loss can occur.
          Set explicit="true" to force declaration of all variables.
          -->
          <compilation debug="true" strict="false" explicit="true" />
          <pages>
          <namespaces>
          <clear/>
          <add namespace="Syst em"/>
          <add namespace="Syst em.Collections"/>
          <add namespace="Syst em.Collections. Specialized"/>
          <add namespace="Syst em.Configuratio n"/>
          <add namespace="Syst em.Text"/>
          <add namespace="Syst em.Text.Regular Expressions"/>
          <add namespace="Syst em.Web"/>
          <add namespace="Syst em.Web.Caching"/>
          <add namespace="Syst em.Web.SessionS tate"/>
          <add namespace="Syst em.Web.Security "/>
          <add namespace="Syst em.Web.Profile"/>
          <add namespace="Syst em.Web.UI"/>
          <add namespace="Syst em.Web.UI.WebCo ntrols"/>
          <add namespace="Syst em.Web.UI.WebCo ntrols.WebParts "/>
          <add namespace="Syst em.Web.UI.HtmlC ontrols"/>
          </namespaces>
          </pages>
          <!--
          The <authentication > section enables configuration
          of the security authentication mode used by
          ASP.NET to identify an incoming user.
          -->

          <authenticati on mode="Windows"/>
          <!-- The <customErrors > section enables configuration
          of what to do if/when an unhandled error occurs
          during the execution of a request. Specifically,
          it enables developers to configure html error pages
          to be displayed in place of a error stack trace.
          -->
          <customErrors mode="off" />
          <globalizatio n fileEncoding="w indows-1256" requestEncoding ="utf-8" responseEncodin g="utf-8" culture="en-US"/>
          </system.web>
          </configuration>[/code]

          plz if any changes required in web.config file reply
          thanx a lot for your replies
          Last edited by Frinavale; Oct 31 '07, 06:25 PM. Reason: Added [code] tags to make more legible

          Comment

          • Plater
            Recognized Expert Expert
            • Apr 2007
            • 7872

            #6
            With custom errors set to off, is it possible an error is occuring that you cannot see?

            Comment

            • rahemeen
              New Member
              • Sep 2007
              • 11

              #7
              dear peter
              plz help me out same session expiring very shortly after logging in and i am and my expert friends suggested that may be unhandled exception is causing this session expiry. can you plz tell me how to get rid of unhandled exception or how to know where unhandled exception is raising.

              thanx in advance

              Comment

              • Plater
                Recognized Expert Expert
                • Apr 2007
                • 7872

                #8
                Change the setting that hides errors from users to off (so that errors will show up in page)
                Use the page until you find an error.
                OR run the project in debug mode and see if Visual Studio catches any errors.

                Comment

                • rahemeen
                  New Member
                  • Sep 2007
                  • 11

                  #9
                  Visual Studio does not catch any error it perfectly shows build succeeded and that dll iam uploading on server. and i changed web.config file and i did <customErrors mode="On" /> but still no error raising and supposing i have a page to add new poll after logged in i am accessing this page and after filling the form when i click on save button it is going to login page. without saving the data. each logged in user page is i am able to accessing first time after log in when i use it or press any button it is redirecting to login page.

                  Comment

                  • Plater
                    Recognized Expert Expert
                    • Apr 2007
                    • 7872

                    #10
                    I am NOT talking about a build succeeding(alth ough at least that part is working), I am talking running in debug mode.

                    Comment

                    • rahemeen
                      New Member
                      • Sep 2007
                      • 11

                      #11
                      s dear i ran in debug mode also build succeeded and for your information my web application is running fine on my pc. no session expire problem nothing iam able to login and until sign out my page is working fine. no problem working on my pc.but problem is online. after i uploaded my application on web server online this problem i am facing offline on pc i have no prob. with my web application

                      Comment

                      • Plater
                        Recognized Expert Expert
                        • Apr 2007
                        • 7872

                        #12
                        Does your browser block the cookies sent by your online server?
                        The session number is kept as a cookie on the client side and is required for it to work correctly.

                        Comment

                        • rahemeen
                          New Member
                          • Sep 2007
                          • 11

                          #13
                          below is my code when in page_load i check session variables and allow page to be browsable plz check the code & let me know is it correct or not.

                          //*************** *************** *************** *************** ********
                          [code=vbnet]
                          Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArg s) Handles Me.Load
                          If Not Session("USERID ") > 0 Then
                          Response.Redire ct("UserLogin.a spx")
                          Else
                          If Not Session("ROLE") = "Administra tor" Then
                          Response.Redire ct("usercp.aspx ")
                          End If
                          End If
                          If Not IsPostBack Then
                          FillCategories( )
                          End If[/code]
                          //*************** *************** *************** *************** ********
                          above code when i do some save button click or some action after loged in page expires and goes to UserLogin.aspx page

                          what is wrong in this code can u tell me plz
                          Last edited by Frinavale; Oct 31 '07, 06:27 PM. Reason: Added [code] tags to make more legible

                          Comment

                          • Plater
                            Recognized Expert Expert
                            • Apr 2007
                            • 7872

                            #14
                            I would guess that the trouble is on the client-browser side.
                            Check to make sure your client-browser is set to allow cookies and session cookies

                            Comment

                            • Frinavale
                              Recognized Expert Expert
                              • Oct 2006
                              • 9749

                              #15
                              Originally posted by rahemeen
                              below is my code when in page_load i check session variables and allow page to be browsable plz check the code & let me know is it correct or not.

                              //*************** *************** *************** *************** ********
                              [code=vbnet]
                              Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArg s) Handles Me.Load
                              If Not Session("USERID ") > 0 Then
                              Response.Redire ct("UserLogin.a spx")
                              Else
                              If Not Session("ROLE") = "Administra tor" Then
                              Response.Redire ct("usercp.aspx ")
                              End If
                              End If
                              If Not IsPostBack Then
                              FillCategories( )
                              End If[/code]
                              //*************** *************** *************** *************** ********
                              above code when i do some save button click or some action after loged in page expires and goes to UserLogin.aspx page

                              what is wrong in this code can u tell me plz

                              Try changing your
                              [code=vbnet]
                              If Not Session("USERID ") > 0 Then[/code]
                              to be
                              [code=vbnet]
                              If Not Session("USERID ") Is Nothing Then[/code]


                              Also change
                              [code=vbnet]
                              Session("ROLE") = "Administra tor"[/code]
                              to be
                              [code=vbnet]
                              String.Compare( Session("ROLE") , "Administrator" )=0
                              [/code]

                              Comment

                              Working...