Implementation of Windows Authentication in ASP.NET

By Lalitha Kumaran

Implementation of Windows Authentication in ASP.NET

Web.Config
**********
<connectionStrings>
<add name="ADConnectionString" connectionString="LDAP URL " />
</connectionStrings>

Connectionstring refers LDAP server and add Membership Provider entry inside <System.web>

<membership defaultProvider="MembershipADProvider">
<providers>
<add name="MembershipADProvider"
type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=2.0.0.0,Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="ADConnectionString"
connectionUsername="User1"
connectionPassword="passcode"
attributeMapUsername="sAMAccountName"
/>
</providers>
</membership>

<authentication mode="Forms">
<forms loginUrl="login.aspx" name=".ASPXFORAUTH" defaultUrl="Home.aspx"></forms></authentication>

Default Url :  Redirects to content page once the user is authenticated.

Home Page
*********
1.Add Namespace
using System.Runtime.InteropServices;
using System.Web.Security;

2. OnClick of button(Login) event,add the following code to validate the user
ActiveDirectoryMembershipProvider mm = new ActiveDirectoryMembershipProvider();
if (Membership.ValidateUser(“username”, “passcode”))
{
FormsAuthentication.RedirectFromLoginPage();
}
Else
{
Response.Write(“Invalid userName/Password”);
}


Implementation of Windows Authentication in ASP.NET  (1002 Views)