2

I have a gridview with a list of my users (using the ASP.Net Membership and Profile providers) and I have managed to display all the fields I need. But the problem is that when I access the page that edits the profile of a user or I add a column to the gridview where it displays some field from the profile of the users, these are set as logged on.

Why is this? Can this be avoided?

I need to know the list of the users, and who is really logged in at the moment, but with this problem I can't know because all users are marked as logged in.

Here's the code of my grid view.

   <asp:GridView ID="gvUsers" runat="server" AutoGenerateColumns="False"
DataKeyNames="UserName"
   OnRowCreated="gvUsers_RowCreated" OnRowDeleting="gvUsers_RowDeleting" 
            Font-Size="8pt" Width="700px" CellPadding="4" ForeColor="#333333" 
            GridLines="None" AllowSorting="true">
       <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />

   <Columns>
      <asp:BoundField HeaderText="Usuario" DataField="UserName"/>
      <asp:HyperLinkField HeaderText="E-mail" DataTextField="Email"
         DataNavigateUrlFormatString="mailto:{0}" DataNavigateUrlFields="Email" />
      <asp:TemplateField HeaderText="No. Cliente">
        <ItemTemplate>
           <asp:Label ID="lblCustormerID" runat="server" Text='<%# Profile.GetProfile(Eval("UserName").ToString()).Contacts.CustomerID %>'></asp:Label>
        </ItemTemplate>
      </asp:TemplateField>
      <asp:BoundField HeaderText="Creado" DataField="CreationDate"
         DataFormatString="{0:MM/dd/yy h:mm tt}" />
      <asp:BoundField HeaderText="Ultima Actividad" DataField="LastActivityDate"
         DataFormatString="{0:MM/dd/yy h:mm tt}" />
      <asp:CheckBoxField HeaderText="Activo" DataField="IsApproved"
         HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" >
<HeaderStyle HorizontalAlign="Center"></HeaderStyle>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
       </asp:CheckBoxField>
      <asp:CheckBoxField HeaderText="En Línea" DataField="IsOnline"
         HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" >
<HeaderStyle HorizontalAlign="Center"></HeaderStyle>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
       </asp:CheckBoxField>
      <asp:HyperLinkField Text="<img src='../images/edit.gif' border='0' />"
         DataNavigateUrlFormatString="EditUsers.aspx?UserName={0}"
         DataNavigateUrlFields="UserName" />
      <asp:ButtonField CommandName="Delete" ButtonType="Image"
         ImageUrl="~/images/delete.gif" />
   </Columns>
       <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
       <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
   <EmptyDataTemplate>No se encontraron usuarios.</EmptyDataTemplate>
       <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
       <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
       <EditRowStyle BackColor="#999999" />
       <AlternatingRowStyle BackColor="White" />
</asp:GridView>

I have spent hours googling for an answer without any luck, so your help is greatly appreciated.

Thanks in advance!

crispaul
  • 21
  • 2
  • The issue here is on the page "EditUsers.aspx", and this is the page that you need to invastigate and show here. – Aristos Nov 11 '11 at 03:49
  • Not necessarily. The issue is with EditUsers.aspx and Users.aspx, where the gridview is. The thing is that no matter where, whenever I edit or access a user's profile info, that user gets marked as online. – crispaul Nov 11 '11 at 13:22
  • dont you see ? you say by your self, the problem is when you call the EditUser.aspx. Check this code, or give it here to give you more help. From the code that you have give here there is no clue what doing this issue. – Aristos Nov 11 '11 at 13:56
  • Ok, in the gridview column: The part that says Profile.GetProfile(Eval("UserName").ToString()).Contacts.CustomerID is the one causing this. – crispaul Nov 11 '11 at 15:30
  • In the EditUsers.asp there is a line in the Page_Load that says: Dim profile As ProfileCommon = Me.Profile profile = Me.Profile.GetProfile(Me.UserName) Got it? – crispaul Nov 11 '11 at 15:31
  • No matter where I use that expression (getprofile), the user with that profile is gets displayed as logged in. – crispaul Nov 11 '11 at 15:33

1 Answers1

0

I implemented a similar system on one of my apps recently that used Windows authentication that would work here.

I have a class called ActiveUser which has the fields UserID, UrlRequested and DateRequested, and another class called ActiveSession which has a List(Of ActiveUser). It also has static methods AddUser (which removes any existing item in the list that matches the UserID and then adds a new one) and GetUsers which removes anyone who has a DateRequested older than 10 minutes.

Then in the Global.asax file under Application_Start I set the ActiveSession class up. In Application_BeginRequest I add the user to the list. Then you can bind the list from GetUsers in whatever page you want.

Gavin Ward
  • 1,022
  • 8
  • 12