Various Ways to Share URLs in Google+ Using ASP.NET

Introduction

This article will tell you various ways of sharing URLs on Google+ using ASP.NET.

Google+ allows you to share many things, like videos, links, images, text and so on. You can also do it from your application created in .NET, so you can implement this feature in your application and allow the users to share something.

First Method

In the first method I will simply create an anchor that will help us to share the link.

Write this code for the application and replace "csharpcorner.com" with the URL you want to share:

<body>

    <form id="form1" runat="server">

    <div>

        <a href="https://plus.google.com/share?url=http://www.c-sharpcorner.com">Share on Google+</a>

    </div>

    </form>

</body>

Here nothing needs to be added to the head section, no JavaScript or jQuery is required, only a simple anchor will work for us.

On running the application you will get a link to be clicked as in the following:

share on google plus

Now If I click on the link then a share window will be displayed that will display the URL that you selected, it will also show one of the images from that website.

share on google plus

You can select any image, it will call all the Images and we can select any of the images.

share on google plus

Now If I take you to my Google+ Account then you will see that this URL will be shared there:

share on google plus

It is possible that this simple thing doesn't work for you, because sometimes our Browser doesn't accept the URL in a simple way, in those cases we need to make one change for passing the URL.

Second Method

This method will also use a simple anchor but here the URL will be passed with some added text.

<body>

    <form id="form1" runat="server">

    <div>

        <a href="https://plus.google.com/share?url=http%3A%2F%2Fhttp://www.c-sharpcorner.com%3Fa%3Db%26c%3Dd">Share</a>

    </div>

    </form>

</body>

You can see that I had added some special text just before the sharing URL, this will help the browser to understand the URL more clearly.

Now if I run my application then you will again see an anchor but this time with different text because I have provided new text to it.

share on google plus

On click of this anchor again a share window will be opened where again one image along with the sharing URL will be shown.

share on google plus

Third Method

In this method I will create a Google+ share button, on a click of this button again a sharing window will be opened and will help the user to share the URL.

Write this code:

<body>

    <form id="form1" runat="server">

    <div>

        <div class="g-plus" data-action="share" data-annotation="none" data-href="http://www.c-sharpcorner.com/">

    </div>

    </div>

    </form>

</body>

Here I have created a Div whose class is set is set as g-plus, g-plus helps the browser to identify the Google related things. In this div I have passed the URL in the data-href that will help to share it on the click of the button.

Now on running the application you will see a Google sharing button as in the following:

share on google plus

If I click on this button than again the sharing window will be opened as in the following:

share on google plus

On the click of share again this URL will be shared on my profile.

Up Next
    Ebook Download
    View all
    Learn
    View all