Automatic Redirection from login page to previous page

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pentahari
    New Member
    • Dec 2007
    • 60

    Automatic Redirection from login page to previous page

    Redirect to login page if session("UserNa me") is expired when the page useraccount.asp x load event


    My useraccount.asp x code :

    Code:
    If Session("UserName") Is Nothing Then
        Response.Redirect("../login/login.aspx")
    End If
    The above code works correctly. but my question is the user enter the correct username and password in the login.aspx page . it will automatically redirect to previous page (useraccount.as px; useraccount.asp x is the sample name of the page but i have used the session redirect coding to many pages in my project).
  • Curtis Rutland
    Recognized Expert Specialist
    • Apr 2008
    • 3264

    #2
    Did you make sure to set Session("UserNa me") equal to some value after a successful login? If you forgot to set it, its value would still be Nothing.

    Comment

    • pentahari
      New Member
      • Dec 2007
      • 60

      #3
      Originally posted by insertAlias
      Did you make sure to set Session("UserNa me") equal to some value after a successful login? If you forgot to set it, its value would still be Nothing.
      Sure. I have assign the value to session variable.

      Comment

      • alag20
        New Member
        • Apr 2007
        • 84

        #4
        Originally posted by pentahari
        Redirect to login page if session("UserNa me") is expired when the page useraccount.asp x load event


        My useraccount.asp x code :

        Code:
        If Session("UserName") Is Nothing Then
            Response.Redirect("../login/login.aspx")
        End If
        The above code works correctly. but my question is the user enter the correct username and password in the login.aspx page . it will automatically redirect to previous page (useraccount.as px; useraccount.asp x is the sample name of the page but i have used the session redirect coding to many pages in my project).
        You can try to lock the login by directory. For this you will need to modify your web.config to specify which folder is login restricted and what url is the login page. Once you have done this, normally the redirect is handled by IIS which I would recommend.


        Another option for you is to add the url from which you are directing to the login url as a variable in the url / in a session. On successful login, redirect to that variable url if availlable otherwise the default page. Though I would recommend using the first method!

        Comment

        • kenobewan
          Recognized Expert Specialist
          • Dec 2006
          • 4871

          #5
          Even easier is to use membership class of .net 2.0. HTH.

          Comment

          • pentahari
            New Member
            • Dec 2007
            • 60

            #6
            Thanks for yours post.

            I have solved the problems by store the current page URL to session variable when checking the session expiry, and it call back from after successful login.

            Comment

            • Curtis Rutland
              Recognized Expert Specialist
              • Apr 2008
              • 3264

              #7
              Originally posted by pentahari
              Thanks for yours post.

              I have solved the problems by store the current page URL to session variable when checking the session expiry, and it call back from after successful login.
              I see that I was misunderstandin g your problem. Sorry about that. Glad you solved it.

              Comment

              • pentahari
                New Member
                • Dec 2007
                • 60

                #8
                I have found the easy way to this problem.

                pass the current URL as query string to login page when the check session expiry operation.

                Comment

                • alag20
                  New Member
                  • Apr 2007
                  • 84

                  #9
                  Originally posted by pentahari
                  I have found the easy way to this problem.

                  pass the current URL as query string to login page when the check session expiry operation.
                  Glad to hear that it worked out for you. Though for future you might want to check my other option as it is url encodes the url for you automatically!

                  Comment

                  Working...