LoginView requires two postbacks before showing the correct template

Last post 06-17-2007 8:08 AM by e_screw. 1 replies.

Sort Posts:

  • LoginView requires two postbacks before showing the correct template

    06-16-2007, 12:08 PM
    • Loading...
    • coderGeek
    • Joined on 06-16-2007, 3:48 PM
    • Posts 63
    I have a form with a login and logout button and a LoginView.  When I click the login button I call

    Membership.ValidateUser() and FormsAuthentication.SetAuthCookie()

    after calling these Context.User.Identity.IsAuthenticated still returns false.  Why?  What am I missing.  If I press the button a second time, Context.User.Identity.IsAuthenticated is true.

    Here is the markup:

    <div>

    <%=DateTime.Now %>

    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

    <asp:Button ID="btnLogin" runat="server" Text="Login" OnClick="btnLogin_Click" />

    <asp:Button ID="btnLogout" runat="server" Text="Logout" OnClick="btnLogout_Click" />

    <asp:LoginView ID="LoginView1" runat="server">

    <LoggedInTemplate>logged in at <%=DateTime.Now %></LoggedInTemplate>

    <AnonymousTemplate>logged out<%=DateTime.Now %></AnonymousTemplate>

    </asp:LoginView>

    </div>

     here is the code:

    protected void btnLogin_Click(object sender, EventArgs e)

    {

    contextUserIsAuthenticated = Context.User.Identity.IsAuthenticated;

    pageUserIsAuthenticated = Page.User.Identity.IsAuthenticated;

    bool validUser = Membership.ValidateUser("bar", "barbar");if (validUser)

    {

    FormsAuthentication.SetAuthCookie("bar", true);

    TextBox1.Text = "***logged in***";

    }

    contextUserIsAuthenticated = Context.User.Identity.IsAuthenticated;

    pageUserIsAuthenticated = Page.User.Identity.IsAuthenticated;

    }

    protected void btnLogout_Click(object sender, EventArgs e)

    {

    contextUserIsAuthenticated = Context.User.Identity.IsAuthenticated;

    pageUserIsAuthenticated = Page.User.Identity.IsAuthenticated;

    FormsAuthentication.SignOut();TextBox1.Text = "***logged out***";

    contextUserIsAuthenticated = Context.User.Identity.IsAuthenticated;

    pageUserIsAuthenticated = Page.User.Identity.IsAuthenticated;

    }

     

     

  • Re: LoginView requires two postbacks before showing the correct template

    06-17-2007, 8:08 AM
    Answer
    • Loading...
    • e_screw
    • Joined on 10-20-2004, 9:22 AM
    • Women, Guitar, Russia, Billiards, Nature, .NET
    • Posts 3,852

    This is a re-post of http://forums.asp.net/t/1122885.aspx and you are being answered there

    Thanks

    Mark post(s) as "Answer" that helped you

    Electronic Screw
    Website||Blog||Dub@i.net
Page 1 of 1 (2 items)
Microsoft Communities
Page view counter