Home » Tutorials » ASP.NET » Add Google custom search in asp.net MVC website

Add Google custom search in asp.net MVC website

4 ways to Convert JSON to DataTable in C# - asp.net
Register custom URL Protocol using C# - Windows Application

Add Google custom search in asp.net MVC website

Hello folks, today we will discuss regarding how to add google custom search in asp.net MVC website!! It is very difficult to add full text search or provide whole website search functionality easily. To over come this problem we will see how can we add google custom search in asp.net MVC website. Same way you can also add google search in asp.net website or HMTL website as well.

Step-1:  Setup your google search engine.

To setup your google search engine first go to https://cse.google.com/cse/ -> New search engine -> add your site for which you want to do configuration and hit Create button as shown below image.

 

Google-Seach-console-configuration

 

Step-2: Copy code snippet

Go to Edit Search engine  -> Select your website name  -> Setup -> In Basic tag -> Press on “Get Code” -> Copy code snippet for your future use.

Google-Seach-console-Code-snippet

Step-3: Create new project of MVC in visual studio.

Refer my another post to create MVC project ASP.NET MVC step by step- Hello World!.

Step-4: Add below code in _Layout.cshtml

 

Step-5: Add new “GoogleSearchController” Controller and add below code snippet with Action named with “SearchPosts”.

 

Step-6: Add View for this controller and add below code snippet.

 

Step-7: Add routing to get proper search engine enabled URL by adding below code snippet in RouteConfig.cs as below.

 

Finally we will run our code and it will land on Index page of website as below:

Landing-page-for-Google-Search-MVC

Landing-page-for-Google-Search-MVC

And after searching with specific keyword we will be redirected to result page as show below:

Result-google-search-console-in-mvc-page

Result-google-search-console-in-mvc-page

 

 

About

Hello friends, My self Dhruv Sheth, I have more than 6 years of Industrial experience as a Software Developer. In my career I got chance to work with asp.net, c#,Web API, JavaScript, JQuery, WPF, WCF , Windows Application, PostScript, vb.net, GhostScript etc. So I have decided to share my knowledge with everyone and finally I have come up with TechnoThirsty.

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*

Time limit is exhausted. Please reload CAPTCHA.




DISCLAIMER:
The content is copyrighted to technothirsty.com and may not be reproduced on other websites without permission from the owner.You may contact us using the information below.