LoginView - I'm probably trying to use it in a way that's not intended...

Discussion in 'ASP .Net' started by Homer J. Simpson, Aug 29, 2007.

  1. I think I "get" the basic loginview control, based on form authentication
    samples I keep seeing. I can get basic functionality out of it (works
    great), but the more I try to take it a step beyond (customizing it), the
    more I think my customizations are being done in such a way that doesn't fit
    the mold. I need somebody to either confirm my efforts are futile, or show
    me the right way.

    I have a page with a bunch of controls I'd like to have displayed, whether
    the user is authenticated or not.

    This is followed by a bunch of controls that I want to either show up (if
    the user is authenticated), or stay hidden (if the user isn't) and replaced
    with an asp:Login control. I thought I could do the following:

    [some common header, some text and various controls]
    <asp:LoginView>
    <AnonymousTemplate>
    <asp:Login />
    </AnonymousTemplate>
    <LoggedInTemplate>
    [other controls that should be displayed only if authenticated]
    </LoggedInTemplate>
    </asp:LoginView>

    However, when I hit F5, I get errors (in the page's .cs file) stating that
    all the references to the controls that I've declared within the
    LoggedInTemplate> tags don't exist in the current context. I'm not entirely
    sure why that would be the case, as these controls are only referenced in
    the code-behind within the body of event handlers (eg,
    ListBox1_SelectedIndexChanged(), btnAdd_Click(), etc) that could only
    possibly be invoked when the user is logged in (and thus those controls are
    showing). Both ListBox1 and btnAdd are controls that are part of
    <LoggedInTemplate>. I tried referencing them using variants on
    "LoginView1.ListBox1" and "LoginView1.LoggedInTemplate.ListBox1", but
    IntelliSense doesn't seem to agree with me.

    In any case, in an attempt to work around this particular problem, I've
    tried moving everything I put within <LoggedInTemplate> (outside the whole
    asp:LoginView, actually), and putting everything in an invisible
    panel...with the intent of showing the panel in Page_Load() only if
    HttpContext.Current.User.Identity.IsAuthenticated is true. I think that's
    an ugly kludge, but I'll live with it if that's the way to go. Hitting F5
    doesn't report any problem, but now as soon as the browser loads, I get an
    error saying 'the resource cannot be found'--it's looking for login.aspx.

    I don't *have* this separate login page, nor would I like to get redirected
    to a separate page for this. I want to use the same page, with *some*
    controls showing, and an <asp:Login> control embedded into that if the user
    isn't authenticated. Actually there's a couple of pages that I'd like to
    have implemented in the same fashion--rendering a section of the page and an
    <asp:Login> if appropriate...I don't want a generic login page.

    Am I misinterpreting the form authentication/login mechanism? Do I really
    have to have a dedicated login page, which every other page will redirect
    to?
     
    Homer J. Simpson, Aug 29, 2007
    #1
    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. Samantha
    Replies:
    11
    Views:
    810
    Samantha
    Feb 19, 2005
  2. Martin Maney
    Replies:
    1
    Views:
    307
    Gabriel Genellina
    Apr 11, 2007
  3. Basildk
    Replies:
    8
    Views:
    621
    Patrice
    Aug 31, 2007
  4. epsilon
    Replies:
    2
    Views:
    224
  5. Steven D'Aprano
    Replies:
    42
    Views:
    1,169
    Terry Reedy
    Sep 28, 2008
Loading...

Share This Page