using System; using System.Collections.Generic; //using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Xml; using System.Net; using System.DirectoryServices; using System.Text; namespace CityAutoLogin { public partial class _Default : Page { private const string ACCOUNT = "LG8New"; // GetXML makes the http request in sQueryString and returns the response. private static XmlDocument GetXML(string sQueryString) { HttpWebRequest oRequest = (HttpWebRequest)WebRequest.Create(sQueryString); HttpWebResponse oResponse = (HttpWebResponse)oRequest.GetResponse(); XmlDocument oResponseXML = new XmlDocument(); oResponseXML.Load(oResponse.GetResponseStream()); return (oResponseXML); } protected void Page_Load(object sender, EventArgs e) { try { string Path = User.Identity.Name; // domain\user //WindowsIdentity id = WindowsIdentity.GetCurrent(); //Request.ServerVariables["REMOTE_USER"] //Request.ServerVariables["LOGON_USER"] //Request.ServerVariables["AUTH_USER"] string[] UserPath = Path.Split(new char[] { '\\' }); string UserName = UserPath[UserPath.Length - 1]; // find the user in Active Directory DirectorySearcher Search = new DirectorySearcher(); Search.Filter = String.Format("(SAMAccountName={0})", UserName); Search.PropertiesToLoad.Add("memberOf"); SearchResult rslt = Search.FindOne(); string Group = ""; if (rslt == null) { ErrLabel.Text = "No Group Error"; } else { int GroupCount = rslt.Properties["memberOf"].Count; for (int counter = 0; counter < GroupCount; counter++) { string MemberString = (string)rslt.Properties["memberOf"][counter]; // Update this code to parse MemberString according to how each city has AD set up // MemberString is in LDAP format: // CN=Planning,OU=Planning,DC=dmpclient,DC=local if (MemberString.Contains("OU=Planning")) Group = "Planning"; else if (MemberString.Contains("OU=Public Works")) Group = "PublicWorks"; else Group = "Error"; } } // getSIK - this does the authentication that creates a "Session Initialization Key" // server IP must be registered with DMP for this to work string sQueryString = "http://dc1.parcelstream.com/admin/getSIK.aspx?login=" + UserName + "&account=" + ACCOUNT + "&group=" + Group; XmlDocument oResponseXML = GetXML(sQueryString); XmlNode oNode = oResponseXML.SelectSingleNode("Response/Success"); if (oNode == null) throw (new Exception("Could not authenticate: " + oResponseXML.SelectSingleNode("Response/Error/@message").Value)); // Get Authentication site and key // Success response looks like: // // // // message format is "///" // need to separate the components to generate the input to InitSession string fullSIK = oNode.Attributes["message"].Value; string[] sAuth = oNode.Attributes["message"].Value.Split(new char[] { '/' }); string sDC = sAuth[1]; string sKey = sAuth[2] + "/" + sAuth[3]; // // string sFold = sAuth[2]; string url = string.Format("http://maps.digitalmapcentral.com/production/Dashboard/app/city.aspx?loginPage=http://maps.digitalmapcentral.com/&sik={0}", fullSIK); HttpContext.Current.Response.BufferOutput = true; HttpContext.Current.Response.Redirect(url); //Server.Transfer(url); } catch (Exception ex) { Response.Write(ex.Message); Response.Write(ex.StackTrace); } } } }