1
votes

Currently in My application, validating the users using the ASP.Net membership provider and the ASP.Net default Login page contains only Username and Password. This is working fine with this two fields. But as per my current requirement, need an extra field "Company" display as dropdownlist in ASP.Net Login page and validate the three Company, Username and Password using the ASP.NET membership provider. Is this possible or not, customize the ASP.Net Login page with an extra field using ASP.Net membership provider? Could you please give me some ideas how could I approach?

2

2 Answers

1
votes

Membership provider's ValidateUser method only accept two parameters - username and password. Even if you override it, you cannot pass three parameters.

ValidateUser(string username, string password)

Basically, you cannot use Login control to validate for user. Instead, you want to validate user by yourself. Here is an sample code -

enter image description here

Note: I strip out codes in Login control for demo purpose.

<asp:Login ID="LoginUser" runat="server" OnAuthenticate="LoginUser_Authenticate">
    <LayoutTemplate>
        <asp:TextBox ID="UserName" runat="server" />
        <asp:TextBox ID="Password" runat="server" TextMode="Password" />
        <asp:DropDownList ID="CompanyDropDownList" runat="server">
            <asp:ListItem Text="One" Value="1" />
            <asp:ListItem Text="Two" Value="2" />
        </asp:DropDownList>
        <asp:Button ID="LoginButton" runat="server" CommandName="Login" 
        Text="Log In" ValidationGroup="LoginUserValidationGroup" />
    </LayoutTemplate>
</asp:Login>

protected void LoginUser_Authenticate(object sender, AuthenticateEventArgs e)
{
    var companyName = LoginUser.FindControl("CompanyDropDownList") 
        as DropDownList;

    if(MyValidateUser(LoginUser.UserName, LoginUser.Password, 
        companyName.SelectedValue))
    {
        FormsAuthentication.SetAuthCookie(LoginUser.UserName, false);

        // Do something
    }
}

Please make sure you use new ASP.NET Universal Providers

0
votes

you can use the Profile Provider for this.

Alternatively, you could create your own table(s) that store additional user-related information. This is a little more work since you're on the hook for creating your own tables and creating the code to get and save data to and from these tables, but I find that using custom tables in this way allows for greater flexibility and more maintainability than the Profile Provider (specifically, the default Profile Provider, SqlProfileProvider, which stores profile data in an inefficient, denormalized manner).

Take a look at this tutorial, where you can find a walk through this process: Storing Additional User Information.