<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Google Stop Blog - Make a change &#187; C#</title>
	<atom:link href="http://googlestop.com/blog/category/programming-language/csharp/feed/" rel="self" type="application/rss+xml" />
	<link>http://googlestop.com/blog</link>
	<description>Just another weblog of Charry</description>
	<lastBuildDate>Sat, 07 Jan 2012 09:51:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>ASP.net 发布的小问题</title>
		<link>http://googlestop.com/blog/2008/11/aspnet-%e5%8f%91%e5%b8%83%e7%9a%84%e5%b0%8f%e9%97%ae%e9%a2%98/</link>
		<comments>http://googlestop.com/blog/2008/11/aspnet-%e5%8f%91%e5%b8%83%e7%9a%84%e5%b0%8f%e9%97%ae%e9%a2%98/#comments</comments>
		<pubDate>Thu, 20 Nov 2008 13:13:34 +0000</pubDate>
		<dc:creator>Charry</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Programming Language]]></category>

		<guid isPermaLink="false">http://googlestop.com/blog/2008/11/20/aspnet-%e5%8f%91%e5%b8%83%e7%9a%84%e5%b0%8f%e9%97%ae%e9%a2%98/</guid>
		<description><![CDATA[Exception Details: System.Data.SqlClient.SqlException: Failed to update database &#8220;C:InetpubwwwrootSSRAPP_DATAASPNETDB.MDF&#8221; because the database is read-only. 上面的例子通常发生在publish一个新开发的web application的时候，解决方法很简单：即修改App_Data这个目录的Security属性，加入用户&#8221;NETWORK SERVICE&#8221;，并设置该用户可以对这个目录有Write权限。 [ad]]]></description>
			<content:encoded><![CDATA[<p>Exception Details: System.Data.SqlClient.SqlException: Failed to update database &#8220;C:InetpubwwwrootSSRAPP_DATAASPNETDB.MDF&#8221; because the database is read-only.</p>
<p>上面的例子通常发生在publish一个新开发的web application的时候，解决方法很简单：即修改App_Data这个<strong>目录</strong>的Security属性，加入用户&#8221;NETWORK SERVICE&#8221;，并设置该用户可以对这个目录有Write权限。</p>
<p>[ad]</p>
]]></content:encoded>
			<wfw:commentRss>http://googlestop.com/blog/2008/11/aspnet-%e5%8f%91%e5%b8%83%e7%9a%84%e5%b0%8f%e9%97%ae%e9%a2%98/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C# LDAP Wrapper</title>
		<link>http://googlestop.com/blog/2008/11/c-ldap-wrapper/</link>
		<comments>http://googlestop.com/blog/2008/11/c-ldap-wrapper/#comments</comments>
		<pubDate>Sat, 15 Nov 2008 09:01:42 +0000</pubDate>
		<dc:creator>Charry</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Programming Language]]></category>

		<guid isPermaLink="false">http://googlestop.com/blog/2008/11/15/c-ldap-wrapper/</guid>
		<description><![CDATA[Before you try to run the following code, please download Novel LDAP lib: http://forge.novell.com/modules/xfcontent/downloads.php/ldapcsharp/ldapcsharp/CsharpLDAP-v2.1.10/ using System; using System.Collections.Generic; using System.Text; using Novell.Directory.Ldap; namespace LDAPUtility { class LDAPUtil { private string ldapHost = "ssuzdc3"; private int ldapPort = 389; LdapConnection ldapConn = null; private void Connect() { try { // Creating an LdapConnection instance ldapConn = [...]]]></description>
			<content:encoded><![CDATA[<p>Before you try to run the following code, please download Novel LDAP lib:</p>
<p><a title="http://forge.novell.com/modules/xfcontent/downloads.php/ldapcsharp/ldapcsharp/CsharpLDAP-v2.1.10/" href="http://forge.novell.com/modules/xfcontent/downloads.php/ldapcsharp/ldapcsharp/CsharpLDAP-v2.1.10/">http://forge.novell.com/modules/xfcontent/downloads.php/ldapcsharp/ldapcsharp/CsharpLDAP-v2.1.10/</a></p>
<pre>
using System;
using System.Collections.Generic;
using System.Text;
using Novell.Directory.Ldap;

namespace LDAPUtility
{
    class LDAPUtil
    {
        private string ldapHost = "ssuzdc3";
        private int ldapPort = 389;
        LdapConnection ldapConn = null;

        private void Connect()
        {
            try
            {
                // Creating an LdapConnection instance
                ldapConn = new LdapConnection();

                // Connect function will create a socket connection to the server
                ldapConn.Connect(ldapHost, ldapPort);

                // Bind function with null user dn and password value will perform anonymous bind
                // to LDAP server
                ldapConn.Bind(null, null);
            }
            catch (Exception e)
            {
                // failed to connect to server
            }
        }

        private void Disconnect()
        {
            ldapConn.Disconnect();
            ldapConn = null;
        }

        public string GetSupervisor(string id)
        {
            Connect();

            string boss = "";
            try
            {
                LdapSearchResults lsc = ldapConn.Search("OU=Users,OU=Suzhou,DC=charry,DC=org",
                LdapConnection.SCOPE_ONE,
                "sAMAccountName=" + id,
                null,
                false);

                while (lsc.hasMore())
                {
                    LdapEntry nextEntry = null;
                    try
                    {
                        nextEntry = lsc.next();
                    }
                    catch (LdapException e)
                    {
                        // Exception is thrown, go for next entry
                        continue;
                    }

                    LdapAttribute attribute = nextEntry.getAttribute("manager");
                    boss = attribute.StringValue;
                }
            }
            catch (Exception e)
            {
                // exception
            }

            Disconnect();

            return GetAMAcountName(boss);
        }

        private string GetFullName(string id)
        {
            // CN=Wang, Charry,OU=Users,OU=Suzhou,DC=charry,DC=org
            int end = id.IndexOf("OU=");

            id = id.Substring(3, end - 4);
            id = id.Replace("\", "");

            return id;
        }

        // convert distinguished name to AMAcountName
        public string GetAMAcountName(string id)
        {
            id = GetFullName(id);
            Connect();

            string tmp = "";
            try
            {
                LdapSearchResults lsc = ldapConn.Search("OU=Users,OU=Suzhou,DC=charry,DC=org",
                LdapConnection.SCOPE_ONE,
                "displayName=" + id,
                null,
                false);

                while (lsc.hasMore())
                {
                    LdapEntry nextEntry = null;
                    try
                    {
                        nextEntry = lsc.next();
                    }
                    catch (LdapException e)
                    {
                        // Exception is thrown, go for next entry
                        continue;
                    }

                    LdapAttribute attribute = nextEntry.getAttribute("sAMAccountName");
                    tmp = attribute.StringValue;
                }
            }
            catch (Exception e)
            {
                // exception
            }

            Disconnect();

            return tmp;
        }

        public string GetDisplayName(string id)
        {
            Connect();
            string name = "";
            // get fullname

            try
            {
                LdapSearchResults lsc = ldapConn.Search("OU=Users,OU=Suzhou,DC=charry,DC=org",
                LdapConnection.SCOPE_ONE,
                "sAMAccountName=" + id,
                null,
                false);

                while (lsc.hasMore())
                {
                    LdapEntry nextEntry = null;
                    try
                    {
                        nextEntry = lsc.next();
                    }
                    catch (LdapException e)
                    {
                        // Exception is thrown, go for next entry
                        continue;
                    }

                    
                    LdapAttribute attribute = nextEntry.getAttribute("displayName");
                    name = attribute.StringValue;
                }
            }
            catch (Exception e)
            {
                // exception
            }

            Disconnect();

            return name;
        }

        public string GetEmail(string id)
        {
            Connect();
            string email = "";
            try
            {
                LdapSearchResults lsc = ldapConn.Search("OU=Users,OU=Suzhou,DC=charry,DC=org",
                LdapConnection.SCOPE_ONE,
                "sAMAccountName=" + id,
                null,
                false);

                while (lsc.hasMore())
                {
                    LdapEntry nextEntry = null;
                    try
                    {
                        nextEntry = lsc.next();
                    }
                    catch (LdapException e)
                    {
                        // Exception is thrown, go for next entry
                        continue;
                    }

                    LdapAttribute attribute = nextEntry.getAttribute("mail");
                    email = attribute.StringValue;
                }
            }
            catch (Exception e)
            {
                // exception
            }

            Disconnect();

            return email;
        }

        public static void test()
        {
            string ldapHost = "ssuzdc3";
            int ldapPort = 389;

            try
            {
                // Creating an LdapConnection instance
                LdapConnection ldapConn = new LdapConnection();

                // Connect function will create a socket connection to the server
                ldapConn.Connect(ldapHost, ldapPort);

                // Bind function with null user dn and password value will perform anonymous bind
                // to LDAP server
                ldapConn.Bind(null, null);

                // Searches in the Marketing container and return all child entries just below this
                // container i.e. Single level search
                LdapSearchResults lsc = ldapConn.Search("OU=Users,OU=Suzhou,DC=charry,DC=org",
                LdapConnection.SCOPE_ONE,
                "sAMAccountName=qinick",
                null,
                false);

                while (lsc.hasMore())
                {
                    LdapEntry nextEntry = null;
                    try
                    {
                        nextEntry = lsc.next();
                    }
                    catch (LdapException e)
                    {
                        Console.WriteLine("Error: " + e.LdapErrorMessage);
                        // Exception is thrown, go for next entry
                        continue;
                    }

                    Console.WriteLine("n" + nextEntry.DN);
                    LdapAttributeSet attributeSet = nextEntry.getAttributeSet();
                    System.Collections.IEnumerator ienum = attributeSet.GetEnumerator();
                    while (ienum.MoveNext())
                    {
                        LdapAttribute attribute = (LdapAttribute)ienum.Current;
                        string attributeName = attribute.Name;
                        string attributeVal = attribute.StringValue;
                        Console.WriteLine(attributeName + "value:" + attributeVal);
                    }
                }
                ldapConn.Disconnect();

            }
            catch (Exception e)
            {
                string x = e.Message;
            }

            Console.Read();
        }
    }
}
</pre>
<p>[ad]</p>
]]></content:encoded>
			<wfw:commentRss>http://googlestop.com/blog/2008/11/c-ldap-wrapper/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

