C# – ASP.NET Membership – Need to add custom fields to admin screens

asp.netasp.net-membershipcmembershipmembership-provider

I need to add a Company Name field that is associated with the logins. Later on I need to incorporate that into my existing admin screens for reporting.

I just can't figure out how to get this done. I have tried the add a column to the Membership table and modifying the stored procs but the column will not show up.

Here is the code of my admin page that I need to modify.

<%@ Page Language="C#" MasterPageFile="~/admin.master" %>
<%@ Register TagPrefix="dc" TagName="alphalinks" Src="~/alphalinks.ascx" %>

<script runat="server">
    private void Page_PreRender()
    {
        if (Alphalinks.Letter == "All")
        {
            Users.DataSource = Membership.GetAllUsers();
        }
        else
        {
            Users.DataSource = Membership.FindUsersByName(Alphalinks.Letter + "%");

        }
        Users.DataBind();
    }


</script>

<asp:Content ID="Content1" ContentPlaceHolderID="c" Runat="Server">

<!-- #include file="_nav.aspx -->

<table class="webparts">
<tr>
    <th>Users by Name</th>
</tr>
<tr>
<td class="details" valign="top">

<!-- #include file="_nav3.aspx -->


User Name filter:&nbsp;&nbsp;&nbsp;
<dc:alphalinks runat="server" ID="Alphalinks" />

<br />
    <br />

<asp:GridView runat="server" ID="Users" AutoGenerateColumns="false"
    CssClass="list" AlternatingRowStyle-CssClass="odd" GridLines="none"
    >
<Columns>
    <asp:TemplateField>
        <HeaderTemplate>User Name</HeaderTemplate>
        <ItemTemplate>
        <a href="edit_user.aspx?username=<%# Eval("UserName") %>"><%# Eval("UserName") %></a>
        </ItemTemplate>
    </asp:TemplateField>
    <asp:BoundField DataField="email" HeaderText="Email" />

    <asp:BoundField DataField="comment" HeaderText="Comments" />
    <asp:BoundField DataField="creationdate" HeaderText="Creation Date" />
    <asp:BoundField DataField="lastlogindate" HeaderText="Last Login Date" />
    <asp:BoundField DataField="lastactivitydate" HeaderText="Last Activity Date" />
    <asp:BoundField DataField="isapproved" HeaderText="Is Active" />
    <asp:BoundField DataField="isonline" HeaderText="Is Online" />
    <asp:BoundField DataField="islockedout" HeaderText="Is Locked Out" />
</Columns>
</asp:GridView>

</td>

</tr></table>


</asp:Content>

I appreciate any help on this please.

Thank you,

Steve

Best Answer

Edit: Don't modify the stored procs or the tables created with the membership provider. This is asking for trouble. What you need to do is add a Profile Provider, which extends the standard user information.

Original Answer: Have a read of this article by Scott Guthrie: http://weblogs.asp.net/scottgu/archive/2006/01/10/435038.aspx It is about the Table Profile Provider, which is a lot better than the out of the box one.

This one too: http://weblogs.asp.net/scottgu/archive/2005/10/18/427754.aspx