Add Site Search to your ASP.NET website

Zoom allows you to add a search engine to your ASP.NET website by using our ASP.NET wrapper with our high performance CGI search application. Click here to find out how.

To find out more about Zoom, visit our homepage.

System Requirements for using Zoom with ASP.NET

For indexing your website, you will require a computer with:

  • Windows 98/2K/XP (and Internet Explorer 5 or later)
  • 64 megs of memory (more memory is required to index larger sites)
  • At least 3 megabytes of available disk space.

For online searching,

  • Web server with CGI executable permissions
  • Web server running Windows with .NET.
  • Intel, AMD or compatible CPU.
  • Server-side write permissions for logging of search results (Optional)

Q. How do I create an ASP.NET (or ASPX) search page?

First, you must have downloaded and installed Zoom on your computer, and indexed your website using the CGI platform option. This will create a set of index files and a working CGI search page. Please see our Users Guide for more information on this step.

You can then create an ASP.NET search page which executes the CGI search function, and return the results, thereby allowing you to integrate Zoom into your ASP.NET website seamlessly.

The following is a C# example (click here if you prefer a VB.NET example) that can be copy and pasted into your ASPX page to do this. Note that you only need to paste this in one ASPX page (eg. "search.aspx"), which will act as the main page where your search results will be shown. For instructions on how to insert a search forms on the other ASPX pages of your website, see this FAQ.

<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Diagnostics" %>
<%@ Page Language="C#" %>
<%
string paramStr = "";
int parampos = Request.RawUrl.IndexOf("?");
if (parampos >= 0)
    paramStr = Request.RawUrl.Substring(parampos + 1);

ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = Server.MapPath("search.cgi");
psi.EnvironmentVariables["REQUEST_METHOD"] = "GET";
psi.EnvironmentVariables["QUERY_STRING"] = paramStr;
psi.EnvironmentVariables["REMOTE_ADDR"] = Request.ServerVariables["REMOTE_ADDR"];
psi.RedirectStandardInput = false;
psi.RedirectStandardOutput = true;
psi.UseShellExecute = false;
Process proc = Process.Start(psi);
proc.StandardOutput.ReadLine(); // skip the HTTP header line
string zoom_results = proc.StandardOutput.ReadToEnd(); // read from stdout
proc.WaitForExit();
// Print the output
Response.Write(zoom_results);
%>

You will also have to make the following changes (this is important):

  • Change the contents of "search_template.html" appropriately (since the output of the CGI is now within your ASPX file, you probably would not need another set of <html> or <head> tags)
  • Specify the "LinkBack URL" setting in the indexer configuration window (under the "Advanced" tab). This will allow links generated by the CGI (eg. for "Next page of results", etc.) to point to the file where you have pasted the above code, rather than the CGI itself. For example, if you have included the above code in "mysearch.aspx", then you should specify "mysearch.aspx" as your LinkBack URL.
  • Check the "Disable charset enforcing on search script" option in the Advanced tab of the Configuration window. This is no longer possible since HTML is being displayed before the search script begins to output.

You should now have a functioning ASP.NET search page.

Troubleshooting

If you are using a specific encoding on your website (which you have set in the Zoom Indexer Configuration window, under the "Languages" tab), but your web server is defaulting to a different encoding, then you may be seeing garbled characters on your search page.

If this is the case, locate the following lines in the above code:

// Print the output
Response.Write(zoom_results);

And replace them with:

// Print the output
Encoding enc = proc.StandardOutput.CurrentEncoding;
byte[] output = enc.GetBytes(zoom_results);
Response.Write(Encoding.GetEncoding("UTF-8").GetString(output));

This assumes you are using UTF-8 as your selected website encoding. For different encodings, replace "UTF-8" with the charset name, eg. "windows-1251", "iso-8859-2", etc. For more information, check the Microsoft documentation for Encoding.

VB.NET Example (to run the CGI version of Zoom on an ASPX page)

Note that the rest of the instructions in the above section also applies here, when using VB.NET to embed the CGI version into an ASPX page. Note that you only need to paste this in one ASPX page (eg. "search.aspx"), which will act as the main page where your search results will be shown. For instructions on how to insert a search forms on the other ASPX pages of your website, see this FAQ.

<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Diagnostics" %>
<%@ Page Language="VB" %>
<%

Dim paramStr As String = ""
Dim parampos As Integer = Request.RawUrl.IndexOf("?")
If (parampos >= 0) Then
    paramStr = Request.RawUrl.Substring((parampos + 1))
End If
Dim psi As ProcessStartInfo = New ProcessStartInfo
psi.FileName = Server.MapPath("search.cgi")
psi.EnvironmentVariables("REQUEST_METHOD") = "GET"
psi.EnvironmentVariables("QUERY_STRING") = paramStr
psi.EnvironmentVariables("REMOTE_ADDR") = Request.ServerVariables("REMOTE_ADDR")
psi.RedirectStandardInput = false
psi.RedirectStandardOutput = true
psi.UseShellExecute = false
Dim proc As Process = Process.Start(psi)
proc.StandardOutput.ReadLine
Dim zoom_results As String = proc.StandardOutput.ReadToEnd
' read from stdout
proc.WaitForExit
' Print the output
Response.Write(zoom_results)
%>

Q. How do I create a search form on my ASPX pages?

If you wish to add simple search boxes to the other ASPX pages of your site, you can do so by inserting the following HTML:

<input type="text" name="zoom_query" size="20"><br><br>
<input type="button" value="Search" onClick="window.location='http://www.mysite.com/search.aspx?zoom_query=' + this.form.zoom_query.value" >

You will need to replace the URL in the above HTML (in bold) with the actual URL to your search page that you created earlier. Make sure to retain the "?zoom_query=" part at the end.

Note that this method is different to the one described for non-ASPX pages here because ASPX pages usually have an all encompassing <form runat="server"> tag, and it is not possible to have another <form> tag within the main form.

Return to the Zoom Search Engine Support page