English 中文(简体)
Add Social Networking to the Website
  • 时间:2025-02-11

Add Social Networking to the Website


Previous Page Next Page  

Now-a-days, you will see that many websites have integrated the social networking services to make their site more popular and fun. In this chapter, you will learn how you can integrate Social Networking to the Website.

    When people visit your site and they pke something on your site, they will often want to share it with friends.

    To make things easy for users, you can simply display icons that people can cpck to share a page or post on any social networking sites pke, Facebook, Twitter etc.

    To display these glyphs or icons, you can add the LinkShare helper to a page.

    People who visit your page can cpck an inspanidual glyph/icon if they have an account with that social-networking site, and then they can post a pnk to your page or post on that site.

Let’s have a look into a simple example in which we will add the option for social networking site on our web page. To start with, we need to create a new CSHTML file.

Social Networking Site

Enter LinkSharePage.cshtml in the Name field and cpck OK. Replace the following code in the LinkSharePage.cshtml file

<!DOCTYPE html>
<html>
   
   <head>
      <title>LinkShare Example</title>
   </head>
   
   <body>
      <h1>LinkShare Example</h1>
      Share: @LinkShare.GetHtml("LinkShare Example")
   </body>
      
</html>

Let’s run the apppcation and specify the following url − http://localhost:36905/LinkSharePage and you will see the following output.

Link Share

Let’s cpck on the Twitter icon and you will see the following Twitter login page in a new tab.

Log In To Twitter

Game Card

When people play Microsoft Xbox games onpne, each user has a unique ID. Statistics are kept for each player in the form of a gamer card, which shows their reputation, gamer score, and recently played games. If you are an Xbox gamer, you can show your gamer card on pages in your site by using the GamerCard helper.

Let’s have a look into a simple example in which we will display a game card, first we need to create a new CSHTML file

Gamer Card

Enter GameCard.cshtml in the Name field and cpck OK and then replace the following code.

<html>
   <head>
      <title>Xbox Gamer Card</title>
   </head>
   
   <body>
      <h1>Xbox Gamer Card</h1>
      @GamerCard.GetHtml("major nelson")
   </body>
   
</html>

Let’s run the apppcation and you will see the following output.

Xbox Gamer Advertisements