Creating a Gravatar ASP.NET Control

by David Kiff 14. February 2009 10:30

Introduction

This article provides an ASP.NET Gravatar control that allows you to add Gravatars to your .NET enabled sites easily.

If you are using a framework, such as Joomla for your website, there might already be a plug-in available (http://en.gravatar.com/site/implement). More...

Tags: ,

Gravatar | ASP.NET

Global.asax Session_Start Not Firing

by David Kiff 1. August 2007 12:18

I have spent an hour trying to work out why the session start was not firing within my global.asax file! It turns out that I was adding it to a pre-complied application!

Don't make my mistake!

Tags:

ASP.NET

Extending the GridView to sort Custom Entity Classes

by David Kiff 1. February 2007 03:32

This article aims to provide a way to extend the GridView control to enable it to sort your custom entities.

The custom entities I am discussing are ones like “Customer”, “Order” etc that you may have within your system.  With n-layer applications becoming more popular the use of custom entities is increasing.  Often users will bind an array of these entities to Microsoft’s GridView control and then struggle when it comes to enable sorting.  Unfortunately the GridView control will not automatically sort your custom entities out-of-the-box.

If you bind your array of entities to a GridView and select enable sorting, you will get the following error:
"The GridView ‚GridView1‚ fired event Sorting which wasn't handled." More...

Tags: ,

ASP.NET

Active Directory and ASP.NET Forms

by David Kiff 16. December 2006 07:28

My Final Year Project requires Active Directory Authentication, ASP.NET has a very simple GUI to set this up although I have used LDAP to create finer grained code- more customisable :D. Here is the method I have used:

public bool IsAuthenticated(string domain, string username, string pwd)
{
    string domainAndUsername = domain + @"\" + username;
    DirectoryEntry entry = new DirectoryEntry(_path, domainAndUsername, pwd);
    try
    {
        // Bind to the native AdsObject to force authentication.
        Object obj = entry.NativeObject;
        DirectorySearcher search = new DirectorySearcher(entry);
        search.Filter = "(SAMAccountName=" + username + ")";
        search.PropertiesToLoad.Add("cn");
        SearchResult result = search.FindOne();
        if (null == result) { return false; }
        // Update the new path to the user in the directory
        _path = result.Path;
        _filterAttribute = (String)result.Properties["cn"][0];
    }
    catch
    {
        throw
    }
    return true;
}

If you want to create a simpler AD login we can use the ASP.NET Login control with Memberships.  Example memberships code for the web.config file:

<membership defaultProvider="ADMembershipProvider">
    <providers>
        <clear/>
        <add name="ADMembershipProvider" type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="ActiveDirectory" connectionUsername="userName" connectionPassword="password" attributeMapUsername="sAMAccountName" enableSearchMethods="true" requiresUniqueEmail="true"/>
    </providers>
</membership>

The Login Control can utilize the membership:

<asp:Login ID="LoginControl" runat="server"
                  EnableTheming="true"
                  DisplayRememberMe="true"
                  FailureText="Login attempt has failed.">
</asp:Login>

To me it seems more beneficial to use the first option, the membership way is easier although you require administration rights for the connection.

Tags:

ASP.NET | Active-Directory