0

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;
    }
1
  • Also this post is somewhat helpful, but as far as I can tell does not come up with a solution to do what I need (call internal method to handle AD authentication from the handled OnAuthenticate event) stackoverflow.com/questions/821395/… Commented Jan 2, 2014 at 14:16

1 Answer 1

1

I dont think programaticaly handling AD codes ( your own) is a good attempt. but asp.net provider model is an outstanding practice. you can extend the provider model. the following links provides you what you actually looking.

http://msdn.microsoft.com/en-us/library/ff650308.aspx

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks, to clarify, I did the steps on this page already, so AD authentication does work. However I think I need to handle the onauthenticate event to use either database or AD authentication, and here is where I get lost, it seems I have to code for both AD and database authentication if I handle that event.
Rob, let me know i understood your problem correctly. I think you have to integrate AD authentication also some custom authentication with your own logic also rob check this link codeproject.com/Articles/265870/…
Thanks for the link, this got me to where I wanted to be. I did need a small procedure to do the AD lookup.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.