Search code examples
c#asp.netforms-authenticationmaster-pages

Forms authentication won't let me leave the loginUrl page when user is not logged


i had a previous bad experience with Forms Authentication using iframe, so i created a new web site using ASP.NET and C# using two master pages, one is supposed to be shown when the user is not logged in, and the second one when he is logged.

The problem is this, on all of my pages i have this code in the Pre Init function:

        bool logged = (System.Web.HttpContext.Current.User != null) &&     System.Web.HttpContext.Current.User.Identity.IsAuthenticated;
        if (logged)
        {
            MasterPageFile = "~/MasterL.master";
        }
        else
        {
            MasterPageFile = "~/MasterUL.master";
        }

Anyway when the user is logged it works, i can see all the content pages in the 'logged' master page, but when the user is logged out it won't let me leave the 'Default.aspx' which is a content that is defined as the loginUrl in the web.config, or any other content page i define as loginUrl.

The same pages i have in the not logged master page are the same as in the logged master pages.

i tried debugging, removed any code that says redirect in the code behind, and still i can't find why it behaves like that.

Hope someone could help me with that (note i'm pretty new to master pages and i'm not sure if i'm doing anything wrong).

Thank you.


Solution

  • To allow anonymous access it should either have

    <authorization> 
        <allow users="?" />
    </authorization>
    

    which is for all pages, or another configuration which is setup anonymous access page by page.