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";
}
}
}
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;
{
// 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;
}
Nitin SontakkePosted Dec 22, 2016, 4:41 AM
Hazel MahmudPosted Dec 22, 2016, 1:15 AM
i have the coding below to retrieve calendar but i got the the error atthe line that i have yellow highlighted. what is wrong with it..how to fix it?..please help.
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Sybase.Data.AseClient;
using DayPilot.Web.Ui.Enums.Calendar;
using DayPilot.Web.Ui.Events;
using Microsoft.Exchange.WebServices.Data;
using System.Net;
public partial class Home : System.Web.UI.Page
{
string nopkj;
string mail;
DataTable dt;
protected void Page_Load(object sender, EventArgs e)
{
string emailA = String.Format("(&(objectCategory=person)(sAMAccountName={0}))", HttpContext.Current.User.Identity.Name.Split(new char[] { '\\' })[1]);
mail = ad_session.GetADmail(emailA);
lblUserID.Text = mail;
LoadAppointments();
private ExchangeService Service
{
get
{
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013);
// service.Credentials = new WebCredentials("lina77", "dalia31102003@");
service.Credentials = new WebCredentials(CredentialCache.DefaultCredentials);
// service.Url = new Uri("https://outlook.office365.com/ews/exchange.asmx");
service.Url = new Uri("exchange.asmx");
return service;
}
}
private CalendarFolder FindDefaultCalendarFolder()
{
return CalendarFolder.Bind(Service, WellKnownFolderName.Calendar, new PropertySet());
}
private CalendarFolder FindNamedCalendarFolder(string name)
{
FolderView view = new FolderView(100);
view.PropertySet = new PropertySet(BasePropertySet.IdOnly);
view.PropertySet.Add(FolderSchema.DisplayName);
view.Traversal = FolderTraversal.Deep;
SearchFilter sfSearchFilter = new SearchFilter.IsEqualTo(FolderSchema.FolderClass, "IPF.Appointment");
FindFoldersResults findFolderResults = Service.FindFolders(WellKnownFolderName.Calendar, sfSearchFilter, view);
return findFolderResults.Where(f => f.DisplayName == name).Cast<CalendarFolder>().FirstOrDefault();
}
private void LoadAppointments()
{
DateTime startDate = DayPilot.Utils.Week.FirstDayOfWeek();
DateTime endDate = startDate.AddDays(7);
CalendarFolder calendar = FindNamedCalendarFolder("Calendar");
CalendarView cView = new CalendarView(startDate, endDate, 50);
cView.PropertySet = new PropertySet(AppointmentSchema.Subject, AppointmentSchema.Start, AppointmentSchema.End, AppointmentSchema.Id);
FindItemsResultsAppointment> appointment = calendar.FindAppointments(cView);
DayPilotCalendar1.ViewType = ViewTypeEnum.Day;
DayPilotCalendar1.DataStartField = "Start";
DayPilotCalendar1.DataEndField = "End";
DayPilotCalendar1.DataIdField = "Id";
DayPilotCalendar1.DataTextField = "Subject";
DayPilotCalendar1.DataSource = appointment;
DayPilotCalendar1.DataBind();
DayPilotCalendar1.Update();
}
}
}
Nigel FernandesPosted Dec 22, 2016, 12:47 AM
Nitin SontakkePosted Dec 21, 2016, 10:15 PM
Hazel MahmudPosted Dec 21, 2016, 8:59 PM
Nitin SontakkePosted Dec 21, 2016, 9:37 AM
Hazel MahmudPosted Dec 21, 2016, 7:51 AM
Nitin SontakkePosted Dec 21, 2016, 3:48 AM