Forms Authentication auto-redirect not working

Last post 06-08-2008 3:45 AM by LockH. 19 replies.

Sort Posts:

  • Re: Forms Authentication auto-redirect not working

    06-06-2008, 1:32 PM
    • All-Star
      17,038 point All-Star
    • guru_sarkar
    • Member since 08-31-2007, 12:00 AM
    • Posts 2,578

    not sure but just an idea if this has something to do with authorization or roles

  • Re: Forms Authentication auto-redirect not working

    06-06-2008, 2:55 PM
    Answer
    • Member
      point Member
    • mark88
    • Member since 06-02-2008, 1:54 PM
    • Posts 15

    <pages theme="Default" smartNavigation="true">

     

    Set smartNavigation="true" in web.config and that solved it for now.  Will have to test further.  Don't understand what is different between desktop Vista VS 2005 to Laptop XP Pro VS 2005.  I'm not setting smartnavigation reference in config on desktop and redirecting works fine.

    Does this make any sense?

  • Re: Forms Authentication auto-redirect not working

    06-07-2008, 4:27 AM
    • Contributor
      2,793 point Contributor
    • LockH
    • Member since 03-25-2007, 2:58 PM
    • Scotland, where whisky has no e.
    • Posts 576

    This is a well known gotcha in ASP.NET 2.

    User A tries to go to page XX but is not authorised to view it, because not logged in.

    Gets sent to login page, logs in ok, gets sent back to page XX. Happy bunny.

     

    User B tries to go to page XX but is not authorised to view it. B is already logged in, but not in the role required to view page XX.

    Gets sent to login page. Logs in again as B, gets sent back to page XX. Still not in the role required to view page XX, gets sent back to login page.

    User B tells everybody your site is broken, the login control doesn't work.

     

    The fix is to intercept authorised users on arrival at the login page, and check to see if the returnurl is set.

    If so, send them to a "Sorry, you are not allowed to view that page".

    If not (ie, not logged in, or logged in but without a returnurl, which means they came here by choice) let them login.

     

    Here is the code you need for your login page. You can cook up your own Unauthorised.aspx.

    protected void Page_Load(object sender, EventArgs e)

    {

    if (!Page.IsPostBack)

    {

    if (Request.IsAuthenticated && !string.IsNullOrEmpty(Request.QueryString["ReturnUrl"]))

    // This is an unauthorized, authenticated request...

    Response.Redirect("~/Unauthorised.aspx");

    }

    }

    If a post helps to solve your problem, please click the Answer button on that post.

    I'm still confused, but now I'm confused on a higher plane.
  • Re: Forms Authentication auto-redirect not working

    06-07-2008, 7:16 PM
    • Member
      point Member
    • mark88
    • Member since 06-02-2008, 1:54 PM
    • Posts 15

    I understand what you're saying and do have code in my login.aspx to handle that.

    This problem arose suddenly.  I was developing an asp.net 2 site on my desktop.  Periodically, every couple of weeks or so, I would load the project on my laptop to develope when I was away.

    I noticed suddenly one time that the automatic redirect built into forms authentication failed to work properly.  I have a asp:loginstatus control that would display "login" when I wasn't authenticated.  If I clicked on that control to take me to login.aspx, if I was on default.aspx which is able to viewed by all, default.aspx would refresh, I would not be taken to login.aspx.  Instead default.aspx would postback and be totally blank white with nothing displayed.

     Another thing, If I put login.aspx into the address bar I can get to logn.aspx and successfully login.  When I went to click continue on the welcome back screen, login.aspx would post back and be totally blank white.  The continue handler is simply a response.redirect(returnurl).

    I saw something with smartnavigation causing blank white pages to appear so thought I would give it a try.

    Don't know why this would only happen when I was developing on my laptop and have had no problem on my desktop.

  • Re: Forms Authentication auto-redirect not working

    06-08-2008, 3:45 AM
    • Contributor
      2,793 point Contributor
    • LockH
    • Member since 03-25-2007, 2:58 PM
    • Scotland, where whisky has no e.
    • Posts 576

    Different versions of IIS could be a factor.  Wonder if it would look the same in Firefox?

    If a post helps to solve your problem, please click the Answer button on that post.

    I'm still confused, but now I'm confused on a higher plane.
Page 2 of 2 (20 items) < Previous 1 2