We are using the ASP.NET AD authentication via <asp:Login> container. I'd like to add some functionality to either do AD authentication (which currently works without me generating code) or database authentication.
I handled the Authenticate event to optionally make the database call if configured in the web.config, however it seems to be all or nothing. Either I have to do both the AD and the database authentication by code or just use AD. Can I handle the database stuff and pass thru AD authentication and let the system handle it (e.g. how it is doing it now behind the scenes?).
The problem is right now I do not have any code to handle the AD stuff, so if I am using AD, then the handled event is called, the auth variable is populated to false, and the login fails. I'd like to do the AD stuff but not necessarily write a bunch of code (if I have to that is fine).
Here is my asp.net code.
<asp:Login id="ADLogin" runat="server" destinationpageurl="Summary.aspx" width="250px" ForeColor="White"
DisplayRememberMe="False"
remembermetext="Remember me next time on this computer" titletext=""
usernamelabeltext="User Name: " passwordlabeltext="Password: "
onloggedin="ADLogin_LoggedIn" onloginerror="ADLogin_LoginError"
onloggingin="ADLogin_LoggingIn"
onauthenticate="ADLogin_Authenticate">
</asp:Login>
Here is my c# code for the event.
protected void ADLogin_Authenticate(object sender, AuthenticateEventArgs e)
{
// i am not sure if i want to rewrite all of the AD stuff.
bool useAD = (ConfigurationManager.AppSettings["UseActiveDirectory"].ToString() == "true") ? true : false;
bool auth = false;
if (!useAD)
{
auth = IsDatabaseUser(ADLogin.UserName, ADLogin.Password);
}
else // call base method?? (or something??)
{
}
e.Authenticated = auth;
}