how to redirect to a requested page instead of default page after login

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • savvy

    how to redirect to a requested page instead of default page after login

    I able to redirect the user to the index.aspx page after every
    successful login, but I dont want certain pages outside the folder to
    have a access to general public. So if they click that particular link
    or button i want them to be re-directed to the login page and after
    successful login i want to them to view the requested page.
    Can i redirect the users to the login page using
    Reponse.Redirec t("js/login.aspx");
    in the button click event? or is there any other way?
    how we can we get the url so that i can transfer to the respective
    page?
    I know we should use FormsAuthentica tion.SetAuthCoo kie of
    FormAuthenticat ion.Getredirect Url for this purpose but i dont have any
    idea how this works.
    Any ideas will be greatly appreciated

    At the moment i'm using this code

    private void btnlogin_Click( object sender, System.EventArg s e)
    {
    bool blnAuthenticati on =
    Authenticate(tx tusername.Text, txtpassword.Tex t);
    if(blnAuthentic ation)
    {

    FormsAuthentica tion.RedirectFr omLoginPage(txt username.Text,f alse);
    Session["isMemberLogged In"]= true;
    Response.Redire ct("index.aspx" );
    }
    else
    {
    Session["isMemberLogged In"]= false;
    lblErr.Text = "Your Login was invalid. Please try
    again.";
    }
    }

  • osh

    #2
    Re: how to redirect to a requested page instead of default page after login

    When using Forms Authentication, and navigating to a page that requires
    authentication should redirect to the login.aspx page (or a page
    specified in the <forms loginUrl> tag in the web.config file)... .NET
    will automatically append your login.aspx with ?ReturnUrl=[page the
    user tried to access un-authenticated]. You could just request this
    like so...

    if (Request.QueryS tring["ReturnUrl"] != null)
    {
    Response.Redire ct(Request.Quer yString["ReturnUrl"]);
    }
    else
    {
    Response.Redire ct("default.asp x");
    }

    Comment

    • osh

      #3
      Re: how to redirect to a requested page instead of default page after login

      Also, FormsAuthentica tion.RedirectFr omLoginPage will redirect to the
      default page specified in your <forms defaultUrl> tag in your
      web.config file or redirect to the requested page.

      Comment

      • Karl Seguin

        #4
        Re: how to redirect to a requested page instead of default page after login

        RedirectFromLog inPage does 2 things, 1 it sets a cookie and 2 it redirects
        (smartly as described by others).

        If you want more control over the process, you can do those two steps
        yourself.

        To set the cookie, youse FormsAuthentica tion.SetAuthCoo kie (which take the
        same parameters as RedirectFromLog inPage I believe) and then do a
        Response.Redire ct.

        karl

        --
        MY ASP.Net tutorials
        Programming blog exploring Zig, Elixir, Go, Testing, Design and Performance



        "osh" <osh.sean@gmail .com> wrote in message
        news:1132319861 .257857.40340@g 44g2000cwa.goog legroups.com...[color=blue]
        > Also, FormsAuthentica tion.RedirectFr omLoginPage will redirect to the
        > default page specified in your <forms defaultUrl> tag in your
        > web.config file or redirect to the requested page.
        >[/color]


        Comment

        • savvy

          #5
          Re: how to redirect to a requested page instead of default page after login

          Thanks for all your replies and time
          I still got a small problem , it may be silly but
          In the button click event i 'm redirecting the page as
          Response.Redire ct("js/savedjobs.aspx" );
          when it actually goes to the savedjobs.aspx page its redirected back to
          the login.aspx as the member is not logged in. Therefore my URL will be
          always pointing to default page.
          i'm not able to get the requested page..
          I know i'm going wrong somewhere.
          Is that the right way redirection ?
          How can i grab the required page URL
          using Response.Redire ct(Reaquest.Que rystring["ReturnUrl"]);
          Thanks in Advance

          Comment

          • savvy

            #6
            Re: how to redirect to a requested page instead of default page after login

            Thanks for all your replies and time
            I still got a small problem , it may be silly but
            In the button click event i 'm redirecting the page as
            Response.Redire ct("js/savedjobs.aspx" );
            when it actually goes to the savedjobs.aspx page its redirected back to
            the login.aspx as the member is not logged in. Therefore my URL will be
            always pointing to default page.
            i'm not able to get the requested page..
            I know i'm going wrong somewhere.
            Is that the right way redirection ?
            How can i grab the required page URL
            using Response.Redire ct(Reaquest.Que rystring["ReturnUrl"]);
            Thanks in Advance

            Comment

            • savvy

              #7
              Re: how to redirect to a requested page instead of default page after login

              Thanks for all your replies and time
              I still got a small problem , it may be silly but
              In the button click event i 'm redirecting the page as
              Response.Redire ct("js/savedjobs.aspx" );
              when it actually goes to the savedjobs.aspx page its redirected back to
              the login.aspx as the member is not logged in. Therefore my URL will be
              always pointing to default page.
              i'm not able to get the requested page..
              I know i'm going wrong somewhere.
              Is that the right way redirection ?
              How can i grab the required page URL
              using Response.Redire ct(Reaquest.Que rystring["ReturnUrl"]);
              Thanks in Advance

              Comment

              • Karl Seguin

                #8
                Re: how to redirect to a requested page instead of default page after login

                Not sure I understand,
                if you take osh's solution and mine and combine it into a super-solution,
                things should work.

                Use SetAuthCookie and use his code:
                if (Request.QueryS tring["ReturnUrl"] != null)
                {
                Response.Redire ct(Request.Quer yString["ReturnUrl"]);
                }
                else
                {
                Response.Redire ct("default.asp x");
                }

                to figure out where to redirect...

                --
                MY ASP.Net tutorials
                Programming blog exploring Zig, Elixir, Go, Testing, Design and Performance



                "savvy" <johngera@gmail .com> wrote in message
                news:1132327796 .395435.247930@ g14g2000cwa.goo glegroups.com.. .[color=blue]
                > Thanks for all your replies and time
                > I still got a small problem , it may be silly but
                > In the button click event i 'm redirecting the page as
                > Response.Redire ct("js/savedjobs.aspx" );
                > when it actually goes to the savedjobs.aspx page its redirected back to
                > the login.aspx as the member is not logged in. Therefore my URL will be
                > always pointing to default page.
                > i'm not able to get the requested page..
                > I know i'm going wrong somewhere.
                > Is that the right way redirection ?
                > How can i grab the required page URL
                > using Response.Redire ct(Reaquest.Que rystring["ReturnUrl"]);
                > Thanks in Advance
                >[/color]


                Comment

                Working...