ASP.NET 4 Social Networking

By Atul Gupta , Sudhanshu Hate , Andrew Siemer
  • 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 4.0 and .NET Framework 4.0 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, this book is ideal for you.

The book starts by planning the essential features of your social network, and then building a 'community framework' that will give your site a solid foundation and enable you to add all your social networking features. You can then go on to create user accounts, profile pages, messaging systems, 'friend' relationships between members, photo galleries, blogs, forums, groups, and more. Along the way you will see MEF, Entity Framework, LINQ, AJAX, C# 4.0, ASP.NET Routing,and other features of ASP.NET 4.0 put to practical and interesting uses. There is also integration with other technologies like Silverlight, Flash, XINHA WYSIWYG editor, reCaptcha, Lucene.NET and Cropper and you also look at custom implementation of authentication and profile features for the website.

This book will show you how to create a scalable, maintainable social network that can support hundreds of thousands of users, complete with multimedia features.

Publication date:
March 2011
Publisher
Packt
Pages
484
ISBN
9781849690829

 

Chapter 1. Social Networking

Given the boom in the Internet and mobile devices industry, people across the world are more connected than ever before. Social networking is the in thing. This book 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. 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.

Communities Galore

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 that allow 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 that 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".

Each of these are really large community sites and can easily boast of having millions of subscribers/members. It is however also interesting to note that of the usually large user population, only a small percentage is typically active and most others are passive users. People may join the sites more for social status, but may not really be active users.

There are also many 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 as LinkedIn, Facebook, and so on, these are very active communities that are able to generate a living by means of advertisements on their community. Some communities like Ning even have a membership fee.

 

Once I have my own social network, then what?


In spite of there being so many social networking sites out there, more still keep cropping up. Everyone wants to build one of their own and think they have a better idea and can do a better job than the next guy. Listed below are some of the key considerations for any social network site that often get missed out.

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 one.

If you have 5,000 users, you will have a fairly steady flow of communication between them. 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 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 inappropriate 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 while to find someone who can take care of this for you like the cloud computing solutions from the likes of Microsoft, Amazon and Google, etc.

POST and SLATES

In October 2007 independent research firm Forrester Research, Inc. introduced a method called POST in its report Objectives: The Key To Creating A Social Strategy (http://www.forrester.com/rb/Research/objectives_key_to_creating_social_strategy/q/id/43656/t/2)—People, Objective, Strategy, and Technology which highlighted the important aspects one should keep in mind when creating a social strategy. These are:

  • People: This is about knowing your target audience's social behaviors and attitudes.

  • Objective: This is about what you want to accomplish. Is it to address some concern of people, is it to talk to them, is it for collaboration etc.

  • Strategy: This is essentially about how you will accomplish your objectives and how this will change your relationship with customers.

  • Technology: This is about selecting and deploying the appropriate technologies. Is it mainly a wiki type site or a blog site or for picture sharing etc.?

These ideas were later published as the book called Groundswell (http://www.amazon.com/Groundswell-Winning-Transformed-Social-Technologies/dp/1422125009). Forrester also has a consulting offering around this methodology (http://www.forrester.com/Consulting/POST).

Another related concept is SLATES. It is a term coined by Professor Andrew McAfee and stands for:

  • Search: Ability to search for information on the site. Note that search is different to query, in that search can be ambiguous and not always fit in the typical WHERE clause of SQL statements.

  • Links: Ability to interconnect pieces of content by linking them together. Allow quick navigation from a content to another.

  • Authorship: Ability for users to author content.

  • Tags: Ability to tag content and organize in a manner that allows an easy way to figure out which content occurs the most and allows navigation to it quickly.

  • Extensions: Ability to provide additional value added information like Amazon does by showing 'People who purchased this book also purchased these additional books'.

  • Signaling: Ability to notice change of state like user being online or offline or some change in profile information and ability to navigate to this changed item directly.

These are important aspects when planning to write a social networking site. We will highlight which of these principles is being used as we discuss the features for the site we will be building.

 

Our social network—Fisharoo


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

In this book, we will not just discuss core concepts with demos in the form of snippets, but 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.

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 we will 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. We will show you some screenshots of the finished product. And we 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. We will be using ASP.NET 4 for the implementation with Visual Studio 2010 as the IDE for this. Along with ASP.NET we will also be leveraging certain features from .NET Framework 4, third party tools, and SDKs in our implementation. We will provide the relevant code inline in the book. The entire code can be downloaded from the Packt website. 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

User accounts are 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 Account 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 reCAPTCHA 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 then crop it suitably. 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, implemented using the URL routing feature of ASP.NET, (www.site.com/profiles/AtulGupta) 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 to see 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 the Friends feature, 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 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, that is sent directly to the user via email. Or you can allow your user to send a message via the site, that 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. We will cover Xinha editor in more detail in later chapters.

Media galleries

There are many communities that are very dependent upon media galleries. An example of this is 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 videos, photos, resumes, or any number of physical files with 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—multi-file 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 creating a Java-based or Active-X-based control, which may require some additional installations to your users' systems, we will look at a Silverlight and also a Flash-based implementation.

With this we will be able to browse to a directory and upload as many files as we want as shown in the following screenshot:

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, that 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 some 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/AtulGupta/my-article-name.aspx.

Forums

Everyone is well aware of what 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 percent focused around this sort of feature in the form of a technical help forum. For our site that centers on helping others figure out how to run an aquarium, we will find this feature useful.

The above screenshot shows how the message board will look.

Groups

Groups to me are a form of container for like-minded individuals. It allows a community to pool its resources. A group could comprise of 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 are used, the more 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 applying 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. The screenshot below shows how tagging or commenting can be done.

Mark as Answer

For any forum to be successful, it is important to have the basic infrastructure to post a question and reply. Once this is available, the next important thing is to ensure resolution/responses to posted queries because ultimately that is what will drive the number of users to the forums. To ensure forums are successful, the forums should provide ability to mark a reply as answer. A correctly marked answer will result in specific points being awarded to the user and this helps build his/her reputation on the site.

Voting

Voting is a way to moderate the content on a community site and also recognize people who are contributing by providing valuable comments in forums. Users need to have the right to vote positively and negatively on a question or a reply posted on the forum. This helps other users to not read the entire question and associated replies, but focus on those that are voted higher. Similar to Mark as Answer, Voting also helps build an individual's reputation.

Medals

Once users start to accrue points based on their replies that are either marked as answers or voted in favor of, they start to earn medals. This is a visual indication of their reputation (see the following screenshot) on the site and the higher the number of medals, the higher the confidence that community will have in what this person has to say.

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-layered approach to build our site using Domain-driven design, Model View Presenter, Factory Pattern, and Repository Pattern. We will also make use of Managed Extensibility Framework (MEF), the ADO.NET Entity framework and related tools and Windows Server AppFabric that Microsoft has provided with .NET 4 as well as a few great open source tool sets such as Lucene.NET, and MemCached.

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 discuss how application can be tiered, transformed into Service Oriented Architecture (SOA), deployment on IIS and look at some key concepts around web farming. We will discuss how to create and search indexed data with Lucene.NET. We will also cover how to optimize your data retrieval and content creation by implementing a caching farm inside your web farm using the new Windows Server AppFabric or MemCached Win32 server. We can also 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 and looked at some examples of successful community sites. Next, we discussed key features that a community site must provide and also briefly looked at POST and SLATES. Finally, we discussed what features we will build through the course of this book.

About the Authors

  • Atul Gupta

    Atul Gupta is Principal Technology Architect at the Microsoft Technology Center, Infosys Technologies Limited. He has over 15 years of experience working on Microsoft technologies. His expertise spans User Interface technologies and he has worked extensively withASP.NET. His current focus is on Windows Presentation Foundation (WPF), Silverlight and other technologies like Surface, Pivot, Windows Touch and rich data visualization. In his career spanning over 15 years, Atul has also worked on COM, DCOM, C, C++ before getting onto .NET in year 2001. He has worked on all .NET version and alongside worked on Server products like Commerce Server and BizTalk Server. He has authored papers and handbooks that are available at Infosys’ Technology Showcase (http://www.infosys.com/microsoft/resour ... wcase.aspx). He also blogs along with other Infosys colleagues at http://blogs.infosys.com/microsoft. His involved in community activities like forums, speaking session as part of Virtual TechDays and other such events got him the Microsoft Most Valuable Professional Award for 6 years in a row.

    Browse publications by this author
  • Sudhanshu Hate

    Sudhanshu Hate is Senior Technology Architect with Microsoft Technology Center (MTC), Infosys Technologies Limited. He has over 12 years of industry experience with last seven years on Microsoft .NET Currently his technology area of interestare .NET 4core framework and server side technologies such as WCF 4, WF 4, Entity Framework 4, WCF Data Services and App Fabric to name a few. Sudhanshu has authored papers that are available at Infosys’ Technology Showcase (http://www.infosys.com/microsoft/resour ... wcase.aspx), presented in external forums such as Microsoft Virtual TechDays, 3rdIndiaSoftware Engineering Conference (ISEC 2010) and blogs at http://blogs.infosys.com/microsoft Prior to this, Sudhanshu led Business Intelligence and Legacy Modernization solution development initiatives, and consulted to fortune 500 customers in EMEA and US across .NET, J2EE, ORACLE and Delphi technologies.

    Browse publications by this 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