In the previous blog, we have seen about creating Bing custom search instance through custom search portal. Now, we are going to see implementing the Bing custom search instance in the ASP.Net web application.
Using this you can create own search service for your organization either in .Net platform or in Sharepoint applications. Let's see, how to create the web application.
Open Visual Studio on your computer.
On the File Menu, select New, and then choose Project.
In the New Project window, select Visual C# / Web / ASP.NET core web application, name your project, and then click create.
Once the solution gets created, open the solution file and in the Solution Explorer, expand Pages and double-click index.cshtml to open the file
In index.cshtml, delete everything starting from line 7 and below.
- @page
- @model IndexModel
- @{
- ViewData["Title"] = "Home page";
- }
Then add a line break element and div section to act as container
- @page
- @model IndexModel
- @{
- ViewData["Title"] = "Home page";
- }
- <br />
- <div id="customSearchPortal"></div>
While creating the custom search instance you might have published the Hosted UI to consume your Bing custom search instance. Please navigate to custom search instance you created then in the Hosted UI page, scroll down to the section titled consuming the UI. Click the Endpoints to access the Javascript snippet. You can also get to the snippet by clicking production and then the Hosted UI tab. ( Please refer previous blog).
Paste the script container you added.
- @page
- @model IndexModel
- @{
- ViewData["Title"] = "Home page";
- }
- <br />
- <div id="customSearchPortal">
- <script type="text/javascript"
- id="bcs_js_snippet"
- src="https://ui.customsearch.ai /api/ux/rendering-js?customConfig=<YOUR-CUSTOM-CONFIG-ID>&market=en-US&safeSearch=Moderate&version=latest&q=">
- </script>
- </div>
In the Solution Explorer, right click on wwwroot and click View in Browser.
Your new custom search web page should look like this,
By this application you can do external web search and bring the results from the sites you indexed in the Bing custom search instance. Happy learning !!