c# LDAP create new active directory user

public static string CreateUserAccount(string ldapPath, string userName, string userPassword)
{
    string oGUID = string.Empty;
    try
    {
        //    for example an ldap path : 
        //    10.20.12.11:389/OU=PORTAL,DC=TESTDOMAIN,DC=entptst,DC=local
        string connectionPrefix = "LDAP://" + ldapPath;
        DirectoryEntry dirEntry = new DirectoryEntry(connectionPrefix, "TESTDOMAIN\\admin", "secret");
        DirectoryEntry newUser = dirEntry.Children.Add("CN=" + userName, "user");
        newUser.Properties["samAccountName"].Value = userName;
        newUser.CommitChanges();
        oGUID = newUser.Guid.ToString();

        //If you dont have an SSL connection you can not set password
        newUser.Invoke("SetPassword", new object[] { userPassword });
        newUser.Properties["LockOutTime"].Value = 0;

        //Enable user
        int val = (int)newUser.Properties["userAccountControl"].Value;
        newUser.Properties["userAccountControl"].Value = val & ~0x2;

        newUser.CommitChanges();


        dirEntry.Close();
        newUser.Close();
    }
    catch (System.DirectoryServices.DirectoryServicesCOMException E)
    {
        //DoSomethingwith --> E.Message.ToString();

    }
    return oGUID;
}

Get URL without QueryString in ASP.NET

Is there an easy way to get the url part without the query string of a given Url?

Yeap .

string  sample = Request.Url.GetLeftPart(UriPartial.Path);

Or long way:

string stringUri = “https://blog.bugrapostaci.com/test.aspx?lang=en”;
Uri uri = new Uri(stringUri);
string query = uri.Query;
string url = stringUri.Substring(0, stringUri.Length – query.Length);

happy tips.bye.

Remote Debugging Access Denied Visual Studio 2008

Check both remote and local machine Windows Firewall entries.

In Remote Machine:
Open and Check  Remote debugger monitor and go to Tools -> Permissions and grant the user’s permission to Allow Debug.

One thing that can be missing is File and Printer sharing on the remote machine should open the following ports: TCP 139TCP 445UDP 137, and UDP 138.

Even if you have configured properly remote debugger and set permission correct but still getting “access denied” error when remote debugging . Possibly, your account for network connection is differnt from as server remote debuggers defined user. you may store a credental for target server before remote debugging and its username/password not match servers user for debugging.

You can remove stored networks passwords for specific targets in your client computer.

Control Panel->User Accounts->manage your networks passwords

opens “Stored Usernames and Passwords” windows.

Select account and click  remove button .Try again for remote debugging.

Asp.net Disable postback LinkButton

Add fallowing code to your page_load HTML:

<asp:LinkButton ID="myLinkButton" runat="server" Text="Click Me"></asp:LinkButton>

Code:
protected void Page_Load(object sender, EventArgs e)
{
myLinkButton.Attributes.Add("onClick", "return false;");
}

Happy tips&tricks :)