Social bookmarking is often thought of as being something used only on blogs. That’s probably because you only see them on blogs, when they in fact could be used at most other types of websites as well. It is a feature that is very easy to add to any ASP.NET page, but I haven’t found any simple code on the web I could use for it. So, as so many times before, I had to create the feature from scratch. In this case it was no problem because it is so simple.

I wanted the usual list of icons at the bottom of every web page and thought that a user control was the easiest way to go. So this is what I came up with. Download the user control at the bottom add it to your web project. In the download you’ll also find some icons that is used by the user control. Add those into “/pics/bookmarks/” at the root. You can of course add them where ever you want, but then remember to update the path in the control.

At this control registration to the top of the page:

<%@ Register Src="~/controls/socialbookmarks.ascx" TagName="Bookmarks" TagPrefix="Control" %>

Then add this at the end of the text on your page or anywhere else you want the icons to appear.

<Control:Bookmarks runat="server" id="bookmarks"

  OpenNewWindow="true"

  LinkTitlePrefix="Add to"

  PageTitle="Title of the page"

  PageUrl="http://www.domain.com/thispage.aspx" />

It is very easy to add new bookmark providers to the list as you can see in this method in the user control:

private void AddBookmarks()

{

  AddBookmark("http://digg.com/submit?phase=2&url={0}&title={1}", "Digg");

  AddBookmark("http://del.icio.us/post?url={0}&title={1}", "del.icio.us");

  AddBookmark("http://www.furl.net/storeIt.jsp?u={0}&t={1}", "FURL");

  AddBookmark("http://reddit.com/submit?url={0}&title={1}", "Reddit");

  ...

}

I used this page for finding the links needed to use all kinds of bookmarks and this page for the icons. The whole user control only consist of 2 methods and 4 properties so everyone should be able to customize it.

Download

socialbookmarkcontrol.zip (9,3 kb)

ASP.NET ships with a SqlMembershipProvider and a ActiveDirectoryMembershipProvider that makes user authentication and authorization very easy to implement, but for some reason those are the only membership providers provided natively by ASP.NET 2.0. So, what do you do when you don't want or can't use SQL Server or Active Directory for memberships? You have to build a custom membership provider that suits your needs.

That’s exactly what I faced when I wanted an XML membership provider for a small web project. The only one I could find on the web was a very simple read-only xml provider from MSDN. I then changed it to be writable as well, so you can dynamically add new users among other things. I also encrypted the passwords so no one is able to make sense out of them when looking at the XML file.

It’s plug n’ play, it works and it makes user authentication ridiculously easy. Download the code at the bottom and dump the XmlMembershipProvider.cs class into the App_Code folder and the users.xml into the App_Data folder. Then write this in the web.config.

<membership defaultProvider="XmlMembershipProvider">

  <providers>

    <add name="XmlMembershipProvider" type="XmlMembershipProvider" description="XML membership provider" xmlFileName="~/App_Data/users.xml"/>

  </providers>
</membership>

Now you have a membership provider that enables you to make use of the collection of built in authentication controls. You can also interact directly with the provider without using the built in controls. Here's an example of how to create a new user:

MembershipCreateStatus status;

Membership.Provider.CreateUser("admin", "adminpw", "admin@domain.com", string.Empty, string.Empty, true, "admin", out status);

Even though you can access the provider programmatically, nothing beats the simplicity of the built in controls. To start using the XmlMembershipProvider, drag a CreateUserWizard to your webform and let the magic begin.

Download

XmlMembershipProvider.zip (3,45 KB)