c# - Authenticating an AD user using Membership Provider -
i running weird problem.
synopsis
my login page can authenticate against sql uses or ad users. identify if user ad user, user name should contain backslash.
the logic sql works fine, getting generic error (object reference not set instance of object.
) when authenticating user against ad.
details
for sql users, i've customsqlmembershipprovider()
. call this:
if(membership.provider.validateuser(username, userpassword)) userauthenticated = true;
the class customsqlmembershipprovider()
sends credentials sql database.
for ad users, i've logic:
if (membership.providers["admembership"].validateuser(username, userpassword)) userauthenticated = true;
this above if
statement generating error object reference not set instance of object.
web.config
<add name="connectionstringad" connectionstring="ldap://it.companyname.local" /> ... <membership defaultprovider="customsqlmembershipprovider" userisonlinetimewindow="30"> <providers> <clear/> <add name="customsqlmembershipprovider" type="authentication.membershipproviders.customsqlmembershipprovider" connectionstringname="sqlproviderconnectionstring" enablepasswordretrieval="false" enablepasswordreset="true" requiresquestionandanswer="false" requiresuniqueemail="false" maxinvalidpasswordattempts="5" minrequiredpasswordlength="6" minrequirednonalphanumericcharacters="0" passwordattemptwindow="10" applicationname="/" /> <add name="admembership" type="system.web.security.activedirectorymembershipprovider, system.web, version=4.0.0.0, culture=neutral, publickeytoken=b03f5f7f11d50a3a" connectionstringname="connectionstringad" connectionusername="it\ldapuser" connectionpassword="ldapuserpassword" connectionprotection="secure" maxinvalidpasswordattempts="5" attributemapusername="samaccountname" /> </providers> </membership>
i think there small issue, not figure out.
software
- visual studio 2010
- .net 4.0
- server 2008 r2 sp2 (10.50.4000)
- iis 7.5
its not answer directly few suggestion narrow down problem:
try changing defaultprovider in web.config. set admembership.
break down call:
if (membership.providers["admembership"].validateuser(username, userpassword)) userauthenticated = true;
to
var activedirectoryprovider = membership.providers["admembership"]; if(activedirectoryprovider != null) { userauthenticated = true; } else { log("activedirectoryprovider null"); }
- this wild guess :). rename "admembership" "admembershipprovider" suffixing "provider" in case convention stuff.
Comments
Post a Comment