ASP.NET 3.5 Social Networking

By Andrew Siemer
    Advance your knowledge in tech with a Packt subscription

  • Instant online access to over 7,500+ books and videos
  • Constantly updated with 100+ new titles each month
  • Breadth and depth in over 1,000+ technologies

About this book

Social Networking is all about developing connections or ties between friends and associates. While people have always networked with one another the Internet has allowed us to network with people all over the world easily. Any interest or cause can support its own social network, where fans and followers can meet, chat, and share their views. But building a social networking site from scratch involves some complex logic, and some serious coding.

This book shows how to build a scalable, enterprise-ready social network using ASP.NET. The book uses the latest features of ASP.NET to provide a platform that is efficient, easy to maintain, and extensible. Whether you want to build your own social network, are developing a social site for a customer or employer, or just want a practical guide to developing complex ASP.NET applications then this book is ideal for you.

The book starts by planning the essential features of our social network, and then building a 'community framework' that will give our site a solid foundation and enable us to add all our social networking features. We then go on to create user accounts, profile pages, messaging systems, 'friend' relationships between members, media galleries, blogs, message boards, groups, and more. Along the way you will see LINQ, MVC, AJAX, and other features of ASP.NET 3.5 put to practical and interesting uses.

Publication date:
December 2008
Publisher
Packt
Pages
580
ISBN
9781847194787

 

Chapter 1. Social Networking

This book, as you might have guessed, is all about how to build a social networking site or a community site. In this book, we will take a look at a few well-known social networks and some not-so-well-known networks to get an idea of what features are popular out there. Then we will discuss the community that we will be building in this book. Once we have an idea of what others are doing and what our community will look like, we will dive right in to start building our own demo community.

 

What makes this topic so important


Social networking is all about developing connections or ties between friends and associates. While people have always networked with one another, the Internet has allowed us to do this in a global manner. Some great examples of popular social networks are Digg, LinkedIn, Facebook, and Twitter. Most people have heard of these services and many use them on a daily basis. These communities are able to generate income from advertising and additional paid services.

Large communities

Digg.com is an aggregator of information from other sites. They allow people to post links to interesting videos, blogs, news feeds, and other forms of media and content. This posting is then pushed to the top of their site based on how many others on the site also enjoy that post. Eventually, the posting will fall below the fold and fade into oblivion. The key with their site is that you are not actually viewing the body of the content on their site. This service is essentially a dynamic link farm times ten.

LinkedIn.com has taken the concept of a social network and polished it with a professional touch. With this service you can build a professional profile, connect with recruiters, connect with other professionals in your area, and most importantly, connect with everyone with whom they are connected. LinkedIn has really latched onto the power of the extended network concept.

Facebook.com originally started at Harvard University. This site was essentially a digital version of the book that the school gave to its incoming students so that everyone could get to know one another. This site is very much about building profiles and linking those profiles through an eavesdropping feature that Facebook calls “the wall”. This feature essentially catches all the activity that your friends are performing on the site. The wall is another form of aggregation. Facebook is also well-known for its extensibility features in that it allows developers to create and host applications directly in the Facebook environment.

Twitter.com is what most would call a microblog. This site allows you to post very small blurbs to your blog which are then fed out to your subscribers (friends). This service is largely used for letting people know what you are up to. A great use of this feature is posting: “I am at such and such coffee shop. If anyone is nearby feel free to stop by and have a cup with me.”

Niche communities

Communities listed in the previous section were some examples of large, very accomplished sites. There are far more examples of successful community sites that operate on a much smaller scale. Some of these include Rockero.com, AnimeDates.com, and Ning.com. While not as large or as well-known, these are very active communities that are able to generate a living by means of advertisements on their community.

Rocker.com (created by Jose Nava) is a community that is all about the Latino rock-and-roll scene. This site hosts news, articles, forums, and videos that are all about rock and roll! It has a fairly large following and is an excellent example of a niche site.

AnimeDates.com (created by Adam and Adrianne Wolkov) is a community that brings anime (Japanese cartoons) lovers together. This site puts a twist on the concept of dating in that it tries to bring anime followers together in an intimate way. They have actually had several from their community find the love of their life and get married as a result!

Note

During the writing of this book, AnimeDates.com was acquired by Mania.com. Congratulations Adam and Adrianne!

Ning.com is a community that allows you to build your own community in less than five minutes. This community by itself is large in that its users can create sub-communities that may also be large. But the point of this site is all about creating niche networks. An example of this is http://userinterfacedesign.ning.com/. This community allows its users to discuss the topic of user interface design.

 

Once I have my own social network, then what?


Everyone of my customers is gung ho about having his/her own social network. The customers think they have a better idea and can do a better job than the next guy. What they rarely consider though is that an even moderately successful community site is a lot of work. Some of the unknown requirements for any social network are listed here.

Customer service

In order to keep your site successful you must pay attention to your community. You need to keep your users happy by addressing their needs and by continuously making your site better. A social network is no different from any other business from your customers' perspective. They expect service of some kind or another. The better the service, the more your users will turn to you instead of the next guy.

If you have 5,000 users, you will have a fairly steady flow of communication between them and you. A user might report a broken feature on your site. They may want to shoot the breeze with you. They may need to report another user. They may want to suggest a feature. You need to stay responsive to your users.

It is said that a happy customer will tell a few of his/her friends about the good experience he/she had with your company. An unhappy customer, on the other hand, will tell everyone they know about the bad experience they had with your company. Keep this in mind! The more the users, the more this becomes important.

Content moderation

If you have a lot of users, you (or someone else) will have to manage their activities. They will be adding content to your site on a regular basis. You will need to protect your users from inappropriate content. This means keeping an eye on all of the content in your site. Also as your users will be able to interact with one another through your site, you will need to ensure that there are features that at the very least allow users to protect themselves from other users. If you don't have this sort of feature then you will need a way for your users to report other users to you so that you can deal with it.

If you don't do this, you could end up with at least two problems. You might have a user uploading adult content. This content might offend some of your users. These users could easily take you to court and create havoc for you (even if your terms clearly say that you are not responsible...blah blah blah). The other possible problem is that if a user is offended, he/she may not come back to your site. This may not sound bad, but a social network is all about its users after all!

Growing infrastructure requirements

With any successful site—and not just social networks—it is very important that you keep your infrastructure two steps ahead of your users' needs. If your site is all about video feeds, then you will be required to keep a watchful eye on your bandwidth capabilities and disk space. If either of these starts to fail, the user experience of your site will start to diminish or cease altogether.

If your site has a large number of users regardless of your topic, you will need to watch your web server's usage. You may be required to have your site hosted on many servers. Or you may need to upgrade the overall robustness of your servers to support the heavier demand.

If you are not capable of infrastructure management, it is certainly well worth your will to find someone who can take care of this for you. If you only need part-time care, you might turn to someone like www.geeksontime.com. They provide on and offsite care for infrastructure administration. And don't forget to backup all your data. If this is also not your thing, turn to an automated service such as www.carbonite.com.

 

Our social network—Fisharoo


In this book, we will discuss many of the common features that are required for a social network or community to succeed. We will discuss these features as they pertain to a community that I have long wanted to put up about salt water aquariums, their care, and about the people who are so invested in this hobby.

Unlike many books, we will not just discuss core concepts with demos in the form of snippets. We will build an entire working site from the ground up. And we will build our site in such a way that if by chance you become the founder of the next MySpace, you have a site that will form a great foundation for your community. With that in mind, this book will follow a common problem, design, and solution approach to building the site.

When I tell the story of how and why I want to build a community around the salt water aquarium world, I usually start by saying that salt water enthusiasts are very much like golfers. It is not a hobby where you buy a set of clubs and a few golf balls and then never return to buy anything else. You don't just take your new gear out to the course and proclaim yourself as being a golfer. Generally speaking, people buy a set of clubs, a funny hat and pants, some shoes, some balls, a glove or two. And work at golf a bit. Then they return to the local pro shop to find a better club, a funnier looking hat, perhaps different shoes, better balls, and so on. This repeats until they get to a point where they feel comfortable in their game and can call themselves golfers. Once they have reached this point, they still go to the pro shop forever in search of game improvements.

The salt water enthusiast is very much like a golfer. They buy their first salt water tank as a package with what they think is everything they need to set up a tank. They go home and set up their tank only to find out that the filter they bought was not big enough for their tank. Their lighting is not appropriate for their coral. Their filtration system is not appropriate for their fish. The live rock that they purchased contained a crab, which then started to eat all of their fish. And once the salt water tank is set up in a fashion that it is fairly self-sustaining (they are now a golfer so to speak) the owner wants to add new fish, maybe more fishes, have a bigger tank, and so on.

This social network will focus on helping new and old owners of salt water aquariums set up and take care of their salt water tanks. It will also help them to choose the right fish combinations. And, as it is a community, it will give them a place to go to give advice as well as receive it.

 

This book's approach


In each chapter I will attempt to follow a pattern to build a feature or set of features. We will start with the problem that the chapter addresses. We will then attempt to figure out a design that addresses the feature that we need to build. Finally, we will discuss what is needed to meet the design requirements.

Problem

In the problem section we will outline exactly what we need to do to achieve success for the chapter's topic. I will show you some screenshots of the finished product. And I will cover any major gotchas for building out the features.

Design

This section of each chapter is about defining what exactly we want from a feature or features. Here we will decide on and write down the physical requirements so that in the next section we can start to build out the feature set. Here we will start to look at what the database might look like, whether or not we need to make a page or two, or if a user control might work better, and if an open source tool might help us address our needs.

Solution

In the solution section of our chapters we will discuss how to implement all the requirements for each feature. This section will go deep into the actual code for implementing the feature from the database, out to the user interface. At the end of this section, you should have something that you can play with.

 

Features of our social network


Following are the desirable features that our social networking site will possess:

Accounts

I think that this section of the book is pretty much given on any data-driven site where you have users who are contributing to the site. If you need to know who your users are, then you need some way of tracking their accounts. Instead of showing you accounts from the pure ASP.NET way, this section will show you how to build your own accounting system from scratch.

This will include looking at the registration process where our users create their initial accounts. To make sure that we block bots and other programs from creating accounts in an automated manner, we will implement a CAPTCHA system and discuss some other options that are out there for this. We will implement an email verification system to make sure that our users actually are what they claim to be. With all this in place we will also discuss setting up a permissions system that we can build onto over time. And no chapter on account creation is complete until we discuss password encryptions (an often missed topic).

Profiles

A user's profile is really just an extension of his/her account. The difference being that the account holds the login information and the profile holds all the personal identifiers. It holds the description of the user, the user's attributes, and their photo (avatar). We will discuss creating a user's profile in a way that is flexible enough for all systems to use. We will also discuss how to handle creating an avatar in such a way that a user can upload a picture, and select from that picture only the part that they want to include in their avatar. As the profile contains a great deal of information about the user, we will also implement some forms of privacy to allow them to hide some bits and show others. Finally, we will discuss the creation of a personal page for our user that will allow them to have a vanity URL (www.site.com/AndrewSiemer) to send to their friends.

Friends

The concept of having friends in a community is the glue that keeps people coming back to your site. A friend is a user whom you have stated, whom you trust and allow seeing information about you, and about whom you are generally interested in knowing. Think of a friend as a connection, a colleague, and so on. Different terms describe the same concept for different community topics.

In this section, we will not only show you how to implement friends, but will also discuss how to search for them, find them in the site's listings, and import your contacts into the site to find your friends. We will also implement a microblog in the form of allowing your users to provide a status about where they are and what they are currently doing. This status will then show up on your microblog and your friend's microblog as an alert.

Messaging

Messaging is essential to any community site as it allows users to communicate with one another directly. This can come in many forms. You can send a message to a user, which is sent directly to the user via email. Or you can allow your user to send a message via the site, which is then stored in the recipient's inbox. A notification is then sent out to the recipient. This last form will be easier for you to manage as a site administrator.

In this section we will create a full blown messaging system that will resemble a web-based email application similar to Hotmail or Gmail. As part of our interface we will show a list of existing friends to send messages to. And we will learn how to implement the Xinha WYSIWYG editor in a way that can be re-used easily across the site for complex input.

Media galleries

There are many communities that are very dependent upon media galleries. Some samples of this are YouTube or something similar. This is frequently the feature that can draw the largest percentage of your community back to your site. For that reason, it is very important to understand how to build a media system rather than an image gallery, video gallery, and so on. We will build a generic media management system that will allow you to host video, photos, resumes, or any number of physical files with a limited additional tweaking.

In addition to the media management system, we will take a look at addressing one of the biggest limitations of many web programming environments—multifile upload. ASP.NET is great at handling one file at a time. But when managing a photo gallery, for instance, you will find that you frequently have a handful or hundreds of photos to upload. Rather than create a Java-based or Active-X-based control, which may require some additional installations to your users' systems, we will look at a Flash-based implementation. The Flash player has a pretty large adoption rate, so our tool should load up with little or no problem. With this we will be able to browse to a directory and upload as many files as we want.

Blogging

Blogging is often a major feature in any community site as it gives those who enjoy speaking to the world a tool to do just that. On the other hand though, the output of your blog generates free content for those who are more on the voyeuristic side to read up and follow along with your blogs. One of the biggest benefits for a community with active bloggers is that you are acquiring a large amount of free content to feed the various search engine spiders with. This in turn will help you get your search ranking up, which will drive more traffic to your site, and will in turn grow your community.

With search engines, users, and security in mind, we will invest time to address an issue that plagues many dynamic websites—query string data being used to determine page output. Let's face it, from a user's point of view, seeing a bunch of variable names in the query string with random auto-generated record IDs and 32 character GUIDs is just not that user friendly and at times downright confusing. Add to this that search engines these days seem to be able to navigate some of this query string mumbo jumbo. But we are losing a key opportunity to optimize our site for keywords by spoofing URLs as though our keywords were directories. We will continue from our profile's example and extend our vanity URL support so that we can have something along the lines of www.sitename.com/blogs/andrewsiemer/3may2008/my-article-name.aspx (something of this nature).

Message boards

Everyone is well aware of what a message board or a forum is. For a social network, it is a disconnected form of communication where people can post something to discuss and others can happen across the posted item over time to add their two cents. Frequently in the developer world, you will have a community that is 100% focused around this sort of feature in the form of a technical help forum. For our site which centers on helping others figure out how to run a salt water aquarium, we will find this feature useful.

Groups

Groups to me are a form of containers for like-minded individuals. It allows a community to pool its resources. A group could comprise people who are interested in the same topic, people for or against a certain presidential candidate, or people representing a company. The common focus for a group is that when someone who is part of the group posts content to the site, all the members of that group are notified. If a user sends a message to a group, then all the members become recipients of that message.

In our site, we will support common concepts such as public and private groups. For private groups you will have to request a membership and should be granted access prior to getting into the group. We will also extend the group concept and provide all our groups with a private forum.

Comments

Commenting is just another way of allowing your users to interact with the content and other members of your social network. There isn't a lot that is special about the commenting concept. We will build out a custom user control to handle commenting any physical object in our system that has a supporting table behind it. This means that we can have comments on anything such as photos, videos, profiles, forum postings, blogs, and so on. To sum up, anything can have a comment!

Tags

Tags are very important to the navigation of your community. A tag is usually one or two keywords attached to some content or item in your site. This keyword may be attached to one or many items in the site by one or many users of the site. The more frequently the tag is applied, the larger its subscription base becomes. We can then show the tag in a cloud of other tags. This cloud would be sorted with the most frequently used keywords. Again, the more the keywords used, the larger they get displayed in the cloud.

We can then place a tag cloud in various places of our site such as the homepage, on a user's profile, or on a group's homepage. This will then act as a jumping off point for all of their most frequently tagged content. Usually, this promotes clicking around on the site. The more people move around on the site, the more likely they are to add tags of their own or some other form of content. This will give some activity to your community. We will build our tagging and tag cloud feature as another user control that can be attached to any object with a handful of different display types.

Ratings

Ratings are often a very important part of any community-supplied content site. This allows the whole community to be in charge of what content takes precedence on the site. While the ASP.NET AJAX Toolkit provides us with a rating tool, we will look at creating a custom rating tool. Our rating tool will not only use the AJAX rating tool but will also extend so that rather than apply a rating directly to an item, we can rate individual attributes of an item. All those ratings will then be rolled up, and that score will be the rating that is displayed for the actual item.

This feature will have the ability to be attached to any item in the site as well. Once built, this feature will really help us get the right content for our community. It also provides our users with the sense of belonging as they are now able to provide their opinion on just about anything.

Framework

Anyone can build a mom and pop community site with the features that we discussed. However, if you want to build a site that can grow with your community, we will want to start building it in a certain way from the beginning. For that reason we will follow a few design patterns and concepts upfront. We will use an n-tiered approach to build our site using Domain-driven Design, Test Driven Design, Model View Presenter, Factory Pattern, and Repository Pattern. We will also make use of the new LINQ to SQL tools that Microsoft has recently provided for us as well as a few great open source tool sets such as Lucene.NET, MemCached, StructureMap, and NUnit to name a few.

Scaling up

Once we have our core community built out, we will begin discussing some concepts to help you support a large number of users on your social network. We will start our discussion by looking at some key concepts to web farming. We will then discuss how to create and search indexed data with Lucene.NET. Next, we will cover how to optimize your data retrieval and content creation by implementing a caching farm inside your web farm using the new MemCached Win32 server. Then we can look at optimizing our email communications by implementing some form of mail queuing concepts.

 

Summary


We have taken a look at some of the features that constitute a social networking site. We also looked at some examples of successful community sites and what their niche is. Next, we discussed the community that we will build and why we want to do it. Finally, we discussed what features we will build through the course of this book.

About the Author

  • Andrew Siemer

    Andrew Siemer is currently the enterprise architect at OTX Research. He has worked as a software engineer, enterprise architect, trainer, and author since 1998 when he got out of the Army. Andrew has consulted with many companies on the topics of e-commerce, social networking, and business systems. To name a few, he has worked with eUniverse (AllYouCanInk.com), PointVantage (MyInks.com), Callaway Golf (CallawayConnect.com), Guidance Software (GuidanceSoftware.com), and Intermix Media (Grab.com, AmericanIdol.com, FoxSports.com, FlowGo.com). In addition to his daily duties he also offers various classes in .NET, C#, and other web technologies to local students in his area as well as blogging in his *free* time.

    Browse publications by this author
Book Title
Access this book and the full library for FREE
Access now