views:

415

answers:

2

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

+2  A: 

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

Daniel Dyson
I recognize your intent but you are in no way addressing the problem as state, Daniel. Sorry- -1.
Sky Sanders
The problem as stated is that they want to associate a Company Name with the user's login. The ProfileProvider is the standard asp.net way to do this if you are already using a membership provider. They go hand in hand.
Daniel Dyson
You can wax revisionist all you like, daniel, it doesn't change the fact that your initial answer was a non-sequitur. The advise you later added is valid but don't pretend that you came off the block with a cohesive answer.
Sky Sanders
And if you believe that there is no scenario in which it makes sense to add custom fields to membership as opposed to profile, you are mistaken. If you are going to point a questioner in the opposite direction of their clearly stated requirements you should provider more than a 'dont do that'.
Sky Sanders
Fair enough. I don't quite understand your english, but I have updated my post to reflect the changes that I made from the original. Is this ok?
Daniel Dyson
I realize that my comments might be perceived as defensive, they are not. peace.
Sky Sanders
No worries. Just trying to help the guy out really. I have tried both ways, and using a profile provider was a lot less work. I think it's best if you don't reinvent the wheel. Peace.
Daniel Dyson
Sky Sanders
Thank you guys a lot for you answers but now I am just a little confused. Which way should I go?
Steve
@steve - as you said in another comment - if you need to associate a custom security related field with the user. Membership is the correct place for this type of information. It will be more work but if you gotta have it you gotta have it. Profile could be appropriate for meta-data that does not affect the security of the site, such as the customer name you mentioned, but if you are going to build a membership stack, might as well stuff it all in while you are there.
Sky Sanders
A: 

Steve, are you returning a custom MembershipUser, that you have constructed with the appropriate values, from the custom MembershipProvider that would need to be implemented in order to do this?

If not, then you will need to do so.

If so, you will need to cast the results from Membership, as it's return type is a stock Membership user, even if you are returning a derived type.

something along the lines of..

Users.DataSource = Membership.GetAllUsers().Cast<MyMembershipUser>();
Sky Sanders
Seems like I have to rewrite most of my pages just to add one field? That seems really messed up. There is no easier way? Thank you for all your help, I am just a little frustrated as I wish to better understand this.
Steve
@steve - Well, daniel proposes using profiles, which I agree with in some cases, depending on the volitility and sensitivity of the extra data. it would help clear things up if you describe the type of fields you want to associate with the user and why you chose membership over profile in the first case.
Sky Sanders
I need just one or 2 fields. 1 is Customer Name and another is a value to represent the days that the password is valid for. I chose the Membership because I started coding it that way. No other reason as I am really new to all this.
Steve
@steve - Well, the customer name is a candidate for profiles, but anything related to the password is not and should be stored *with* the password as membership data. So you might as well throw the other field in as well, as it will be less work.
Sky Sanders
@steve - get ready for another adventure and follow the link in my answer (http://msdn.microsoft.com/en-us/library/ms366730.aspx).
Sky Sanders
Ok I will, thank you. Looks like i will have to create a new table with all the login information. I was hoping to keep the existing one and just add 2 fields to it.
Steve
@steve - not necessarily - you should read that tutorial as background on how everything works, then you will have the ammunition you need to make minor changes to the existing infrastructure. Or not. Up to you.
Sky Sanders