Important Notice from AspDotNetStorefront
It is with dismay that we report that we have been forced, through the action of hackers, to shut off write-access to this forum. We are keen to leave the wealth of material available to you for research. We have opened a new forum from which our community of users can seek help, support and advice from us and from each other. To post a new question to our community, please visit: http://forums.vortx.com
Results 1 to 3 of 3

Thread: Is the user logged in?

  1. #1
    sorcerdon is offline Junior Member
    Join Date
    Jan 2011
    Posts
    3

    Question Is the user logged in?

    Hello Experts,

    I have a weird scenario occurring.

    We have a piece of code in the Master Page that should check if a user is logged in or not.
    • If a user IS NOT logged in, then some contents need to be displayed.
    • If a user IS logged in, then no extra contents need to be displayed.


    Here is the code:

    template.master:

    Code:
    <% if (!HttpContext.Current.User.Identity.IsAuthenticated) 
              {%>
                    <SOME CONTENT IS LOCATED HERE>
            <%}%>
    The Behavior:

    This works correctly for all pages - when a user is logged in, the HTML disappears. When a user is NOT logged in the content is displayed.

    The Problem:

    When we navigate to createaccount.aspx, it stops working - it always thinks the user is indeed logged in even though the user has not logged in.

    In order to fix the problem the user has to log in and log out and only then does the master page once again starts working.

    What am I doing wrong?
    Is that the correct way to check if a user is logged in?

  2. #2
    AspDotNetStorefront Staff - Scott's Avatar
    AspDotNetStorefront Staff - Scott is offline Administrator
    Join Date
    Mar 2007
    Location
    Ashland, OR
    Posts
    2,390

    Default

    That's most likely because of this line that fires on page load on createaccount:

    Code:
    ThisCustomer.RequireCustomerRecord();
    That creates a customer record for the current customer in the DB. At that point they're anonymous, but in a manner of speaking they are a customer. I imagine that's going to interfere with the way you're doing that check, on that page and any other that requires a customer.

  3. #3
    cjbarth is offline Senior Member
    Join Date
    Oct 2008
    Posts
    392

    Default

    I've use the following code with no problem:

    Code:
            Public ReadOnly Property IsAuthenticatedUser() As Boolean
                Get
                    Return ThisCustomer.IsRegistered
                End Get
            End Property
    with

    Code:
              <%
                If IsAuthenticatedUser Then
              %>
    ML9.3.1.1
    SQL 2012 Express
    VS 2010
    Azure VM