redirect not working

Ask a Question related to ASP.NET Security, Design and Development.

  1. #1

    Default redirect not working

    I have a login page which does not redirect the user once
    the code has been executed, see below. Whats strange is
    it works perfectly on my localhost when debugging,
    however it fails to redirect when depolyed to a remote
    server. Am I missing any IIS settings or anything? The
    login page just reloads once the login button has been
    clicked.

    Code for the login button:

    private void _btnLogin_Click(object sender,
    System.Web.UI.ImageClickEventArgs e)
    {
    if (IsValidUser(txtUserName.Text,
    txtPassword.Text)) //interacts with the database. This
    method is fine
    {
    if(FormsAuthentication.GetRedirectUrl
    (txtUserName.Text,false)=="/appliedbioscience/index.aspx")
    {
    FormsAuthentication.SetAuthCookie
    (txtUserName.Text,false);
    Response.Redirect
    ("http://www.appliedbioscience.co.uk/appliedbioscience/ind
    ex.aspx",false); //fails here
    }
    else if
    ((FormsAuthentication.GetRedirectUrl
    (txtUserName.Text,false).ToUpper().IndexOf("ADMIN" ) != -
    1) && (string)Session["Role"]!="admin")
    phMsg.Controls.Add(new
    LiteralControl("<font color=red>ERROR: You do not have
    the necessary privellages to administrate this
    site</font>"));
    else

    FormsAuthentication.RedirectFromLoginPage
    (txtUserName.Text,false); //fails here too
    }
    else
    {
    phMsg.Controls.Add(new LiteralControl
    ("<font color=red>ERROR: Invalid Username /
    Password</font>"));
    }
    }

    Thanks,
    Matt


    Matt Owens Guest

  2. Similar Questions and Discussions

    1. ADDT Redirect not working properly
      I have a dynamic list with 3 dynamic forms which sort of act like a wizard where you select the record you want to edit from the dynamic list and...
    2. Response.ReDirect / FormsAuth.ForwardFromLogin not working
      Instead of doing :- FormsAuthentication.SetAuthCookie (txtUserName.Text,false); Response.Redirect...
    3. response.redirect to an HTTPS not working
      I have a web from that based on the user's response needs to go to a web folder set up with SSL. My problem is that when the redirect is executed I...
    4. Response.redirect only working sometimes
      I have response.redirect("/home.asp") in my code but instead of redirecting to that page it sometimes redirects to the current page...
    5. redirect to .net 1.0 assemblies not working
      Snippet from web.config: <startup> <supportedRuntime version="v1.0.3705" /> <requiredRuntime version="v1.0.3705" safemode="true"/> </startup>...
  3. #2

    Default Re: redirect not working

    What do you want to do with this line?

    if(FormsAuthentication.GetRedirectUrl
    (txtUserName.Text,false)=="/appliedbioscience/index.aspx")



    --
    Daniel Fisher(lennybacon)
    MCP C# ASP.NET
    Blog: [url]http://www.lennybacon.com/[/url]

    "Matt Owens" <anonymous@discussions.microsoft.com> wrote in message
    news:422201c4abae$0f994a60$a301280a@phx.gbl...
    >I have a login page which does not redirect the user once
    > the code has been executed, see below. Whats strange is
    > it works perfectly on my localhost when debugging,
    > however it fails to redirect when depolyed to a remote
    > server. Am I missing any IIS settings or anything? The
    > login page just reloads once the login button has been
    > clicked.
    >
    > Code for the login button:
    >
    > private void _btnLogin_Click(object sender,
    > System.Web.UI.ImageClickEventArgs e)
    > {
    > if (IsValidUser(txtUserName.Text,
    > txtPassword.Text)) //interacts with the database. This
    > method is fine
    > {
    > if(FormsAuthentication.GetRedirectUrl
    > (txtUserName.Text,false)=="/appliedbioscience/index.aspx")
    > {
    > FormsAuthentication.SetAuthCookie
    > (txtUserName.Text,false);
    > Response.Redirect
    > ("http://www.appliedbioscience.co.uk/appliedbioscience/ind
    > ex.aspx",false); //fails here
    > }
    > else if
    > ((FormsAuthentication.GetRedirectUrl
    > (txtUserName.Text,false).ToUpper().IndexOf("ADMIN" ) != -
    > 1) && (string)Session["Role"]!="admin")
    > phMsg.Controls.Add(new
    > LiteralControl("<font color=red>ERROR: You do not have
    > the necessary privellages to administrate this
    > site</font>"));
    > else
    >
    > FormsAuthentication.RedirectFromLoginPage
    > (txtUserName.Text,false); //fails here too
    > }
    > else
    > {
    > phMsg.Controls.Add(new LiteralControl
    > ("<font color=red>ERROR: Invalid Username /
    > Password</font>"));
    > }
    > }
    >
    > Thanks,
    > Matt
    >
    >

    Daniel Fisher\(lennybacon\) Guest

  4. #3

    Default Re: redirect not working

    That line detects whether the user has come to the login
    page from the homepage(index.aspx) and if so re-directs
    (doesn't work) them to the index.aspx (I changed it to a
    http:// address in the hope it would work as originally
    it was /appliedbioscience/... type URL).

    The idea behind this is that the user can login and get
    access to the restricted-access documents by logging in
    from the homepage. Otherwise they are taken to the login
    page when they try to access some restricted content and
    are redirected back to the page where they tried to
    download the content from.

    Hope this makes sense.

    Thanks in advance for any pointers you may be able to
    give.
    Matt
    >-----Original Message-----
    >What do you want to do with this line?
    >
    >if(FormsAuthentication.GetRedirectUrl
    >(txtUserName.Text,false)
    =="/appliedbioscience/index.aspx")
    >
    >
    >
    >--
    >Daniel Fisher(lennybacon)
    > MCP C# ASP.NET
    >Blog: [url]http://www.lennybacon.com/[/url]
    >
    >"Matt Owens" <anonymous@discussions.microsoft.com> wrote
    in message
    >news:422201c4abae$0f994a60$a301280a@phx.gbl...
    >>I have a login page which does not redirect the user
    once
    >> the code has been executed, see below. Whats strange is
    >> it works perfectly on my localhost when debugging,
    >> however it fails to redirect when depolyed to a remote
    >> server. Am I missing any IIS settings or anything? The
    >> login page just reloads once the login button has been
    >> clicked.
    >>
    >> Code for the login button:
    >>
    >> private void _btnLogin_Click(object sender,
    >> System.Web.UI.ImageClickEventArgs e)
    >> {
    >> if (IsValidUser(txtUserName.Text,
    >> txtPassword.Text)) //interacts with the database. This
    >> method is fine
    >> {
    >> if(FormsAuthentication.GetRedirectUrl
    >> (txtUserName.Text,false)
    =="/appliedbioscience/index.aspx")
    >> {
    >> FormsAuthentication.SetAuthCookie
    >> (txtUserName.Text,false);
    >> Response.Redirect
    >>
    ("http://www.appliedbioscience.co.uk/appliedbioscience/ind
    >> ex.aspx",false); //fails here
    >> }
    >> else if
    >> ((FormsAuthentication.GetRedirectUrl
    >> (txtUserName.Text,false).ToUpper().IndexOf("ADMIN" ) !
    = -
    >> 1) && (string)Session["Role"]!="admin")
    >> phMsg.Controls.Add(new
    >> LiteralControl("<font color=red>ERROR: You do not have
    >> the necessary privellages to administrate this
    >> site</font>"));
    >> else
    >>
    >> FormsAuthentication.RedirectFromLoginPage
    >> (txtUserName.Text,false); //fails here too
    >> }
    >> else
    >> {
    >> phMsg.Controls.Add(new LiteralControl
    >> ("<font color=red>ERROR: Invalid Username /
    >> Password</font>"));
    >> }
    >> }
    >>
    >> Thanks,
    >> Matt
    >>
    >>
    >
    >
    >.
    >
    Guest

  5. #4

    Default Re: redirect not working

    Hi Matt
    > That line detects whether the user has come to the login
    > page from the homepage(index.aspx) and if so re-directs
    > (doesn't work) them to the index.aspx (I changed it to a
    > http:// address in the hope it would work as originally
    > it was /appliedbioscience/... type URL).
    GetRedirectUrl() Checks if the username is null, returns null in this case,
    or returns Request["ReturnUrl"] if not null or just the path to the
    default.aspx in the root of the application.

    what does this method return in your code?


    --
    Daniel Fisher(lennybacon)
    MCP C# ASP.NET
    Blog: [url]http://www.lennybacon.com/[/url]






    Daniel Fisher\(lennybacon\) Guest

  6. #5

    Default Re: redirect not working

    Daniel,

    Locally the Redirect method returns the correct URL and
    it redirects perfectly. However when I deploy to a web
    server the redirect stops working. I can't debug this
    remotely as I do not have the necessary permissions
    however the code is the same so I can't see how this
    would differ.

    The fact there is a difference between remote and local
    debugging makes me think its perhaps an IIS problem (only
    a guess).

    Any pointers would be much appreciated. Thanks for your
    help

    >-----Original Message-----
    >Hi Matt
    >
    >> That line detects whether the user has come to the
    login
    >> page from the homepage(index.aspx) and if so re-directs
    >> (doesn't work) them to the index.aspx (I changed it to
    a
    >> http:// address in the hope it would work as originally
    >> it was /appliedbioscience/... type URL).
    >
    >GetRedirectUrl() Checks if the username is null, returns
    null in this case,
    >or returns Request["ReturnUrl"] if not null or just the
    path to the
    >default.aspx in the root of the application.
    >
    >what does this method return in your code?
    >
    >
    >--
    >Daniel Fisher(lennybacon)
    > MCP C# ASP.NET
    >Blog: [url]http://www.lennybacon.com/[/url]
    >
    >
    >
    >
    >
    >
    >.
    >
    Guest

  7. #6

    Default Re: redirect not working

    Have you tried to run the code on a different local machine or a VM?

    --
    Daniel Fisher(lennybacon)
    MCP C# ASP.NET
    Blog: [url]http://www.lennybacon.com/[/url]



    <anonymous@discussions.microsoft.com> wrote in message
    news:155e01c4ac50$45979660$a401280a@phx.gbl...
    > Daniel,
    >
    > Locally the Redirect method returns the correct URL and
    > it redirects perfectly. However when I deploy to a web
    > server the redirect stops working. I can't debug this
    > remotely as I do not have the necessary permissions
    > however the code is the same so I can't see how this
    > would differ.
    >
    > The fact there is a difference between remote and local
    > debugging makes me think its perhaps an IIS problem (only
    > a guess).
    >
    > Any pointers would be much appreciated. Thanks for your
    > help
    >
    >
    >>-----Original Message-----
    >>Hi Matt
    >>
    >>> That line detects whether the user has come to the
    > login
    >>> page from the homepage(index.aspx) and if so re-directs
    >>> (doesn't work) them to the index.aspx (I changed it to
    > a
    >>> http:// address in the hope it would work as originally
    >>> it was /appliedbioscience/... type URL).
    >>
    >>GetRedirectUrl() Checks if the username is null, returns
    > null in this case,
    >>or returns Request["ReturnUrl"] if not null or just the
    > path to the
    >>default.aspx in the root of the application.
    >>
    >>what does this method return in your code?
    >>
    >>
    >>--
    >>Daniel Fisher(lennybacon)
    >> MCP C# ASP.NET
    >>Blog: [url]http://www.lennybacon.com/[/url]
    >>
    >>
    >>
    >>
    >>
    >>
    >>.
    >>

    Daniel Fisher\(lennybacon\) Guest

  8. #7

    Default Redirect not working

    I have looked at all the Redirect questions on this site without finding a
    resoultion
    to my redirect problem. I am using sample code to verify a user and
    password from a login page but although the verification is successful and I
    can see that the return url is where I need to go I am continously looped
    back to the login page.
    Cookies are enabled. See code example below.

    --WebConfig--
    <authentication mode="Forms">
    <forms name="TestLoginAthu" path="/" loginUrl="WebForm1.aspx"
    protection="All" timeout="30">
    <credentials passwordFormat="Clear">
    <user name="jeff" password="test" />
    <user name="mike" password="test" />
    </credentials>
    </forms>
    </authentication>

    --Code Behind

    HttpCookie cookie = FormsAuthentication.GetAuthCookie ( TextBox1.Text,
    CheckBox1.Checked );
    // Expires in 30 days, 12 hours and 30 minutes from today.
    cookie.Expires = DateTime.Now.Add(new TimeSpan(30, 12, 30, 0));
    Response.Cookies.Add (cookie);
    string strUrl = FormsAuthentication.GetRedirectUrl ( TextBox1.Text,
    CheckBox1.Checked );
    Response.Redirect( strUrl );
    Ldraw Guest

  9. #8

    Default Re: Redirect not working

    As far as I can tell you have protection set to "All" which uses encryption
    for the cookie. But you are not ecrypting the cookie before you write it to
    the Response stream. I'm not sure how to encrypt a cookie after calling
    GetAuthCookie() but an alternative is to create a FormsAuthentication ticket
    and then use the FormsAuthentication.Encrypt() method passing in the ticket.
    Your sample it should give you the exact same functionality you need. Here's
    a sample:

    //create ticket
    FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1,
    txtUsername.Text, DateTime.Now, DateTime.Now.AddMinutes(30), true,
    string.Empty);
    //encrypt ticket and capture string result
    string sEncryptedTicket = FormsAuthentication.Encrypt( ticket );
    //create a new cookie and add it to the Response stream
    Response.Cookies.Add( new System.Web.HttpCookie(
    FormsAuthentication.FormsCookieName, sEncryptedTicket ) );

    I hope that helps.

    Regards,
    Mark

    "Ldraw" <Ldraw@discussions.microsoft.com> wrote in message
    news:5A215232-5333-4AA1-BA5E-F4AC3BD5FFAE@microsoft.com...
    >I have looked at all the Redirect questions on this site without finding a
    > resoultion
    > to my redirect problem. I am using sample code to verify a user and
    > password from a login page but although the verification is successful and
    > I
    > can see that the return url is where I need to go I am continously looped
    > back to the login page.
    > Cookies are enabled. See code example below.
    >
    > --WebConfig--
    > <authentication mode="Forms">
    > <forms name="TestLoginAthu" path="/" loginUrl="WebForm1.aspx"
    > protection="All" timeout="30">
    > <credentials passwordFormat="Clear">
    > <user name="jeff" password="test" />
    > <user name="mike" password="test" />
    > </credentials>
    > </forms>
    > </authentication>
    >
    > --Code Behind
    >
    > HttpCookie cookie = FormsAuthentication.GetAuthCookie ( TextBox1.Text,
    > CheckBox1.Checked );
    > // Expires in 30 days, 12 hours and 30 minutes from today.
    > cookie.Expires = DateTime.Now.Add(new TimeSpan(30, 12, 30, 0));
    > Response.Cookies.Add (cookie);
    > string strUrl = FormsAuthentication.GetRedirectUrl ( TextBox1.Text,
    > CheckBox1.Checked );
    > Response.Redirect( strUrl );

    Mark Miller Guest

  10. #9

    Default Re: Redirect not working

    Check to see if you have smart navigation turned on for the login page. I had the same problem, turning this off seemed to have solved it.

    --
    Message posted via [url]http://www.dotnetmonster.com[/url]
    rob kelly via DotNetMonster.com Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139