浏览代码

NEW ajout customvar pour google reste a faire cas autre

emmanuel.pheulpin 8 年之前
父节点
当前提交
cdb6701b36

+ 2 - 0
Web/CG67.FicheCollege.Web/CG67.FicheCollege.Web.csproj

@@ -56,6 +56,8 @@
     <Reference Include="System.Data" />
     <Reference Include="System.Data.DataSetExtensions" />
     <Reference Include="System.Data.OracleClient" />
+    <Reference Include="System.DirectoryServices" />
+    <Reference Include="System.DirectoryServices.AccountManagement" />
     <Reference Include="System.Drawing" />
     <Reference Include="System.Web" />
     <Reference Include="System.Web.ApplicationServices" />

+ 7 - 0
Web/CG67.FicheCollege.Web/FicheCollege.aspx

@@ -15,6 +15,13 @@
         _gaq.push(['_setDomainName', '.cg67.fr']);
         _gaq.push(['_trackPageview']);
 
+        _gaq.push(['_setCustomVar',
+      1,                   // This custom var is set to slot #1.  Required parameter.
+      'Visitor',     // The name acts as a kind of category for the user activity.  Required parameter.
+      '<%=user%>',               // This value of the custom variable.  Required parameter.
+      2                    // Sets the scope to session-level.  Optional parameter.
+        ]);
+
         (function () {
             var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
             ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';

+ 53 - 0
Web/CG67.FicheCollege.Web/FicheCollege.aspx.cs

@@ -14,20 +14,73 @@ using System.Xml;
 using CG67.FicheCollege.Service;
 using CG67.FicheCollege.Domaine;
 using System.Collections.Generic;
+using System.DirectoryServices;
+using System.Linq;
+//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\\",""))))
+                using (var directorySearcher = new DirectorySearcher(rootEntry, String.Format("(sAMAccountName={0})", "frederic.bierry")))
+
+                {
+                    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();
+
+                            Response.Write(cnUser);
+
+                            var elu = Groups.Where(x => x.Contains("OU=P2-ELUS")).FirstOrDefault();
+
+                            if (!string.IsNullOrEmpty(elu)) user= elu.Replace("OU=","");
+                            
+                            var mission = Groups.Where(x => x.Contains("OU=E-")).FirstOrDefault();
+
+                            if (!string.IsNullOrEmpty(mission)) user = mission.Replace("OU=","");
+
+                            //cas autre a faire
+
+                        }
+                    }
+                }
+            }
+
+
+            
+
+
+
 
             //Traitement
             XmlDocument entete = new XmlDocument();

+ 5 - 0
Web/CG67.FicheCollege.Web/Web.config

@@ -20,6 +20,11 @@
     <add key="ImpersonationUser" value="service.college"/>
     <add key="ImpersonationPassword" value="2sr72297rN7BzX8QB48t"/>
     <add key="ImpersonationDomain" value="cg67"/>
+    <!-- Configuration de l'accès LDAP -->
+    <add key="USER-LDAP" value="lecturead" />
+    <add key="MDP-LDAP" value="Adlecture!" />
+
+
   </appSettings>
   <system.web>
     <httpHandlers>