| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- 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";
-
- 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);
- }
- }
- }
- }
|