Customize Login Control

A

Andrew Hayes

Added the Login and ValidationSummary controls to the default.aspx page of
VS2005 web application. Set the DestinationPageURL to a different "members
only" page, OnAuthenticate to my custom Authenticate event, and
MembershipProvider to my custom provider.

Converted the Login control to a Template and added an additional <asp:Label
AssociatedControlID=Department ...>Department, <asp:TextBox ID=Department
....> and <asp:RequiredFieldValidator ControlToValidate=Department ...> so I
now have 3 fields to fill in to login. If I don't, the ValidationSummary
control correctly identifies the problem so that all seems to be working.

Created my own Membership Provider, and included a ValidateUser method with
3 string parameters (as well as the usual 2 parameter override), which I
call from the Login1_Authenticate event.

Trouble is, I can't seem to get the 2 things to work together.

If I remove the OnAuthenticate then it correctly goes to the
ValidateUser(string, string) of my custom Provider, but if I include the
OnAuthenticate then it goes to the event OK, but how do I call the custom
ValidateUser method?

Hopefully someone can post the code that goes in the event -

protected void Login1_Authenticate(object sender, AuthenticatedEventArgs e)
{
/* Authenticate using myProvider.ValidateUser(userName, password,
department) somehow? */
}
 
A

Andrew Hayes

A bit more info. This is what the code looks like if I use the normal 2
parameter method for authenticating the users:

protected void Login1_Authenticate(object sender, AuthenticatedEventArgs e)
{
e.Authenticated = Membership.ValidateUser(Login1.UserName,
Login1.Password);
}

That works fine, and I know it uses the overriden ValidateUser in my custom
provider as it hits the breakpoint there, but what I really want it to say
is:

protected void Login1_Authenticate(object sender, AuthenticatedEventArgs e)
{
e.Authenticated = MyMembership.ValidateUser(Login1.UserName,
Login1.Password, Login1.Deparment);
}

But that generates an error. MyMembership doesn't exist in the current
context. OK, so lets change it to Membership then... Another error. The
Login control does not contain a definition for Department. OK, so I replace
Login1.Department with "test" and try again. This time I get a No overload
for ValidateUser takes 3 arguments. Drop the 3rd argument and I'm back to
the working 2 parameter version.

It's probably very simple, but even google doesn't find an appropriate
example.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top