Vishwas Kadamannaya

Vishwas Kadamannaya

  • 1.6k
  • 122
  • 142.5k

ASP.net Web Application with AD Security

Jan 9 2013 7:06 AM
Hi All,
        I need to create a web Application to my company, where only the people who are in a Particular Active Directory group will be able to access the website, and i created a master page and added the code for validating the user for particular AD and it works fine in my local, i have used LDAP, but when i hosted this web application in our server IIS but this code does not work .

using (DirectoryEntry de = new DirectoryEntry("LDAP://" + "Domain")) // domain of user who tries to access website
{
using (DirectorySearcher
adSearch = new DirectorySearcher(de))
{
adSearch.Filter = "(sAMAccountName=" + "User" + ")"; // user who tries to access the website
adSearch.PropertiesToLoad.Add("department");
var result = adSearch.FindOne();
if (result != null)
{
try
{
string department = result.Properties["department"][0].ToString();
}
}
}
}


Any Ideas why this does not work in server and works fine in local, or any of u have done such a webapp.

Thanks in Advance
Vishwa