redirect not working

Discussion in 'ASP .Net Security' started by Matt Owens, Oct 6, 2004.

  1. Matt Owens

    Matt Owens Guest

    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, Oct 6, 2004
    #1
    1. Advertising

  2. 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: http://www.lennybacon.com/

    "Matt Owens" <> wrote in message
    news:422201c4abae$0f994a60$...
    >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\), Oct 6, 2004
    #2
    1. Advertising

  3. Matt Owens

    Guest Guest

    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: http://www.lennybacon.com/
    >
    >"Matt Owens" <> wrote

    in message
    >news:422201c4abae$0f994a60$...
    >>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, Oct 6, 2004
    #3
  4. 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: http://www.lennybacon.com/
    Daniel Fisher\(lennybacon\), Oct 6, 2004
    #4
  5. Matt Owens

    Guest Guest

    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: http://www.lennybacon.com/
    >
    >
    >
    >
    >
    >
    >.
    >
    Guest, Oct 7, 2004
    #5
  6. Have you tried to run the code on a different local machine or a VM?

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



    <> wrote in message
    news:155e01c4ac50$45979660$...
    > 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: http://www.lennybacon.com/
    >>
    >>
    >>
    >>
    >>
    >>
    >>.
    >>
    Daniel Fisher\(lennybacon\), Oct 8, 2004
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Paul
    Replies:
    0
    Views:
    603
  2. Poppy

    Response.redirect not working

    Poppy, Nov 3, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    4,521
    Peter O'Reilly
    Nov 3, 2003
  3. =?Utf-8?B?VHJveQ==?=

    Response.redirect does not redirect from .aspx page

    =?Utf-8?B?VHJveQ==?=, Oct 18, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    5,229
    Srowe1975
    Oct 15, 2008
  4. gaurav tyagi
    Replies:
    14
    Views:
    1,320
    gaurav tyagi
    Jan 20, 2006
  5. Sal
    Replies:
    1
    Views:
    399
Loading...

Share This Page