| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- using System;
- using System.Data;
- using System.Data.OleDb;
- using System.Configuration;
- using System.Collections;
- using System.IO;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Web.UI.HtmlControls;
- using System.Xml;
- using CG67.FicheCollege.Service;
- using CG67.FicheCollege.Domaine;
- using System.Collections.Generic;
- using System.DirectoryServices;
- using System.Linq;
- using System.Text.RegularExpressions;
- //using System.DirectoryServices.AccountManagement;
- namespace CG67.FicheCollege
- {
- public partial class FicheCollege : System.Web.UI.Page
- {
- public string user;
-
- protected void Page_Load(object sender, EventArgs e)
- {
- //Intialisation des paramètres
- //l'année en cours est déclarée dans le fichier de configuration
- int annee = int.Parse(ConfigurationManager.AppSettings["AnneeEnCours"]);
- HttpContext.Current.Session["Annee"] = annee;
- HttpContext.Current.Session["AnneeMoins1"] = annee - 1;
- HttpContext.Current.Session["RNE"] = Request["RNE"];
-
- string domain = "DC=cg67,DC=fr";
-
- //string sUser = ConfigurationManager.AppSettings["USER-LDAP"];
- //string sMdp = ConfigurationManager.AppSettings["MDP-LDAP"];
-
- using (var rootEntry = new DirectoryEntry("LDAP://CG67/" + domain, null, null, AuthenticationTypes.Secure))
- {
- using (var directorySearcher = new DirectorySearcher(rootEntry, String.Format("(sAMAccountName={0})", HttpContext.Current.User.Identity.Name.Replace("CG67\\",""))))
- {
- var searchResult = directorySearcher.FindOne();
- if (searchResult != null)
- {
- using (var userEntry = searchResult.GetDirectoryEntry())
- {
- string cnUser = userEntry.Properties["distinguishedName"].Value.ToString();
- List<string> Groups = new List<string>();
- Groups = cnUser.Split(new[] {"," } , StringSplitOptions.None).ToList();
- var rx = new Regex("OU=[AEFGHIJKLMP]{1}\\-[A-Z]{3,5}", RegexOptions.IgnoreCase);
- user = "AUTRE";
-
- var mission = Groups.Where(x => rx.IsMatch(x)).FirstOrDefault();
-
- if (!string.IsNullOrEmpty(mission)) user = mission.Replace("OU=","");
- if (user == "P-CAB")
- {
- var elu = Groups.Where(x => x.Contains("OU=P2-ELUS")).FirstOrDefault();
- if (!string.IsNullOrEmpty(elu)) user = elu.Replace("OU=", "");
- }
- }
- }
- }
- }
- //Traitement
- XmlDocument entete = new XmlDocument();
- entete.Load(Server.MapPath(@"~/xml/entete.xml"));
- try
- {
- //modif car si code rne null provoque une erreur
- XmlNode xmlFicheCollege = ServiceFiche.GetFicheCollege(Session["RNE"].ToString(), int.Parse(Session["annee"].ToString()));
- this.Title = xmlFicheCollege.SelectSingleNode("college/Etablissement/NomCollegePourPresentation").InnerText;
- xmlFicheCollege.SelectSingleNode("college").InnerXml += entete.DocumentElement.OuterXml;
- this.Xml1.DocumentContent = xmlFicheCollege.OuterXml;
- this.DataBind();
- }
- catch (NullReferenceException nre)
- {
- Console.WriteLine("Erreur de pointeur : null", nre.Message);
- //Response.Redirect("/");
- }
- }
- }
- }
|