Introduction
This is an article which will let you know how to place social media links and icons like Facebook, Google+, C#Corner, Twitter etc. on ASP.NET websites using Model View Controller (MVC) Architecture with the Visual Studio 2015.
Now a days virtually every website has social media integration to gain more traffic on every page they have. I am confident that going through this hub you will learn the process to integrate social media on ASP.NET Websites having model view controller (MVC) architecture.
Before we start
Before we start, the prerequisites are to have knowledge about the basics of ASP.NET Model View Controller (MVC) architecture, coding in Visual Studio, and a little bit about Active Server Pages (ASP).
A bit of things to know about Visual Studio
Visual Studio is a registered product of Microsoft with an integrated development environment to develop computer programs for Windows, Web Applications, Web Services and Mobile Applications for Microsoft Products as well as Android OS. The new version of Visual Studio i.e. VS2015 Community Edition has some great features included by Microsoft and if you like coding with DOT NET framework then upgrade your current development tool with VS2015.
VS2015 is free for developers who would like to code with .net, mobile application development, websites and much more. Individual programming development like engineering projects, desktop applications, web services in .NET etc.,
developed in VS 2015
Visual Studio Community 2015 supports multi-platform apps development for Windows, iOS, Android and more by using single IDE. As per your development need it allows you to build and deploy multi-platform apps or cross-platform apps on any platform for free. To Build and Debug web and cloud modern apps with the use of a free code editor that runs on multiple operating systems like Windows, Linux or OS X.
Basics of MVC
Model is a handler and it is a part of the application that contains actual logic to manage operations with application data.
View is a handler of the application which contains the look and feel of the application or you can say displays of data.
Controller is a handler and it is a part of the application that handles or catches user interactions and it catches all user interactions and sends data to the related model.
Model View Controller (MVC) architecture is better than the old Asp.net web forms and it helps you to manage large scale applications. The MVC parts or you can say that MVC separation helps you to manage complex applications because of focusing on only one aspect at a time. The MVC separation simplifies the group of development with your application development team.
Asp.net Introduction
Active Server Pages (ASP) known as Classic ASP first introduced by Microsoft's server side scripting technology to build websites having extensions .asp
Normally asp pages are written in VBScript. ASP.NET is a newer version or you can say that upgraded version of Active Server Pages having extensions .aspx for better support to web technologies to build user friendly websites with the support of Object Oriented Programming.
An ASP.NET web page supports both C#Script and VBScript and have large sets of XML-based components with back-end programming language support to manage database operations on large scale transactions and security support.
Prerequisites
- Create your own personal profile online with Visual Studio.
- Install and configure Visual Studio 2013+
- Create projects with online Visual Studio website or through Installed version.
- Use Microsoft Azure services to host your website.
- Set backgrounds and startup things for your project.
- Going through this hub, you are climbing a step.
Let's start:
- Open your web browser & go to Visual Studio official website.
Authentication
- Sign In with your own Outlook account. If you don’t have Microsoft account than you should first create it.
Account Creation
- Create a free account on Visual Studio by click on Create a free account now.
Load Dashboard
- Now go to dashboard & open your project in editor by clicking Open in Visual Studio.
Solutions
- Open / Create Solutions by clicking on Open / New links as depicted below.
~/images
- Now first of all download the required images and put it in your website storage like here I will store all images in folder named Image.
Download required images
Update files
- Now open “Default.aspx”, “bootstrap.css” & “Site.master” files & then edit the “Site.master” file as shown below.
Just add this snippet code in Site.master page.
- <!--Social Linking-->
- <asp:ContentPlaceHolderID="social"runat="server"></asp:ContentPlaceHolder>
- <asp:ContentPlaceHolderrunat="server"ID="SocialContentListItems"></asp:ContentPlaceHolder>
Edit Site.master Page
~/Default.aspx
- Now go to “Default.aspx” file and add below mentioned snippets code.
- <asp:ContentID="SocialContent" ContentPlaceHolderID="social" runat="server">
- <divclass="social-links">
- <h5>Follow</h5>
- <arunat="server" href="https://web.facebook.com/codeblankk" target="_blank">
- <imgsrc="image/facebookLogo.jpg" alt="Follow Us on Facebook" />
- </a><br/><br/>
- <arunat="server" href="https://twitter.com/jaidrath_jd" target="_blank">
- <imgsrc="image/twitterLogo.jpg" alt="Follow Us on Twitter" />
- </a><br/><br/>
- <arunat="server" href="http://www.c-sharpcorner.com/members/jaydip-trivedi" target="_blank">
- <imgsrc="image/c-sharpcornerLogo.png" alt="Follow Us on C-sharpcorner.com" />
- </a><br/><br/>
- </div>
- </asp:Content>
Note:
Edit pages like Contact.aspx, About.aspx etc. which is not a part of sub module i.e. “Login.aspx” is a part of sub module known as “Account”.
Default.aspx
~/Account/Login.aspx
- Now go to the page “Login.aspx” which will be in Account folder and edit it with below mentioned snippets code.
- <asp:ContentID="ListItems" ContentPlaceHolderID="SocialContentListItems" runat="server">
- <!--List items mentioned dynamically here !-->
- <lirunat="server" id="SocialListItemDynamic">
- </li>
- </asp:Content>
- <asp:ContentID="SocialContent" ContentPlaceHolderID="social" runat="server">
- <divrunat="server" class='social-links' ID='SocialDiv'>
- <!--Image dynamically added when Page Load-->
- </div>
- </asp:Content>
Login.aspx
~/Account/Login.aspx.cs
- In next step open “Login.aspx.cs” file and update it with below mentioned code.
- string htmlSocialImage = String.Empty;
-
- htmlSocialImage += @ "<h5>Follow</h5> < a runat = 'server'
- href = 'https://web.facebook.com/codeblankk'
- target = '_blank' >
- < img src = '../image/facebookLogo.jpg'
- alt = 'Follow Us on Facebook' / > < /a><br / > < br / >
- < a runat = 'server'
- href = 'https://twitter.com/jaidrath_jd'
- target = '_blank' >
- < img src = '../image/twitterLogo.jpg'
- alt = 'Follow Us on Twitter' / > < /a><br / > < br / >
- < a runat = 'server'
- href = 'http://www.c-sharpcorner.com/members/jaydip-trivedi'
- target = '_blank' >
- < img src = '../image/c-sharpcornerLogo.png'
- alt = 'Follow Us on C-sharpcorner.com' / > < /a><br / > < br / > ";
-
- SocialDiv.InnerHtml = htmlSocialImage;
Login.aspx.cs
~/Content/Site.css
Note: Edit every page with above code which resides in sub modules i.e. Account or other sub modules of your website.
- Now it’s the time you need to update “Site.css” file which resides in Content folder with this snippets code.
-
- .social - links
- {
- position: fixed;
- width: 30 px;
- height: 100 px;
- background - color: #ffffff;
- margin - top: 2.5e m;
- }
-
- .social - linksh5
- {
- color: #808080;
- margin-left: 1em;
- }
-
- .social-linksimg
- {
- margin-left: 1em;
- height: 25px;
- width: 25px;
- position: fixed;
- z-index: -1;
- }
Site.css
Run & Publish
- Now run the application and it’s ready for publishing on the web.
Ctrl + F5 | Execute
- Thanks for reading this article.
If you like the task described in this hub please leave some comments and I might create more articles related to ASP.NET.
Have fun and enjoy doing it yourself.
Read more articles on ASP.NET: