TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Hazel Mahmud
1.4k
315
69.7k
get id and password from active directory
Dec 21 2016 1:36 AM
can anyone help with my problem.. how do i retrieve userid and password from ad_session.aspx and global.asax from Active directory to an aspx.cs page... please help. TQ
my ad_session.cs is as below :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using Sybase.Data.AseClient;
//using session;
using WebApplication_t630staf;
using System.DirectoryServices;
namespace session
{
public class ad_session
{
public static String GetSession(String sFilter)
{
//string ip = "";
string adsPath = "LDAP://staf.ad.uum";
//string adsPath = "LDAP://idms.ad";
//this is optional, but more efficient
string[] attribs = new string[] { "employeeID" };
String username = null;// "idms\\izianti";
String password = null; //"4521";
DirectoryEntry de = new DirectoryEntry(adsPath, username, password, AuthenticationTypes.Secure);
using (de)
{
DirectorySearcher ds = new DirectorySearcher(de, sFilter, attribs, SearchScope.Subtree);
SearchResultCollection sr = null;
sr = ds.FindAll();
int bil = sr.Count;
String nopkj = "";
nopkj = sr[0].Properties["employeeID"][0].ToString();
return nopkj;
}
//return "4754";
}
public static String GetADpass(String pass)
{
//string ip = "";
string adsPath = "LDAP://staf.ad.uum";
//string adsPath = "LDAP://idms.ad";
//this is optional, but more efficient
string[] attribs = new string[] { "employeeID" };
String username = null;// "idms\\izianti";
String password = null; //"4521";
DirectoryEntry de = new DirectoryEntry(adsPath, username, password, AuthenticationTypes.Secure);
using (de)
{
DirectorySearcher ds = new DirectorySearcher(de, pass, attribs, SearchScope.Subtree);
SearchResultCollection sr = null;
sr = ds.FindAll();
int bil = sr.Count;
String passw = "";
passw = sr[0].Properties["password"][0].ToString();
return passw;
}
//return "4754";
}
}
}
my global.asax is as below:
void Session_Start(object sender, EventArgs e)
{
// Code that runs when a new session is started
Session["sFilter"] = String.Format("(&(objectCategory=person)(sAMAccountName={0}))", HttpContext.Current.User.Identity.Name.Split(new char[] { '\\' })[1]);
Session["pass"] = String.Format("(&(objectCategory=person)(password={0}))", HttpContext.Current.User.Identity.Name.Split(new char[] { '\\' })[1]);
//use this code for user testing -->
//Session["sFilter"] = String.Format("(&(objectCategory=person)(sAMAccountName={0}))", "btajudin");
String nopkj = ad_session.GetSession(Session["sFilter"].ToString());//ambil data dari ad dan umpuk ke session
String pass = ad_session.GetADpass(Session["pass"].ToString());//ambil data dari ad dan umpuk ke session
// String nopkj = "4004";
Session["nopkj"] = nopkj;
Session["pwd"] = pass;
}
Reply
Answers (
8
)
Frozen columns kendo gride js
How to change the button to image button based on loading ?