Using Zoom CGI on an ASP.NET website

Zoom allows you to add a search engine to your ASP.NET website with a native ASP.NET Server Control that provides integration possibilities into your ASP.NET application.

For most ASP.NET users, you should use the ASP.NET Server Control and not the method described below.

The following page describes an alternative method that allows you to use the high performance (C++ compiled) CGI on an ASP.NET website by creating an ASP.NET wrapper.

This might be desirable for people who cannot install a Control on the web server, but have CGI executable permissions (and other requirements detailed below).

To find out more about the full Zoom package, visit our homepage.

System Requirements for using the Zoom CGI 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 using ASP.NET (other platforms available),

  • Web server running Windows with .NET support.
  • Web server setup with CGI executable permissions and ASP.NET trust settings which allow process creation.
  • 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
// Print the output

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.

UTF-8 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

And replace them with (C# code below):

// Print the output
Encoding enc = proc.StandardOutput.CurrentEncoding;
byte[] output = enc.GetBytes(zoom_results);

In VB.NET, you can use the following code:

Dim enc As Encoding = proc.StandardOutput.CurrentEncoding
Dim utf8enc As Encoding = Encoding.GetEncoding(“UTF-8”)
Dim output As Byte() = enc.GetBytes(zoom_results)

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)
Dim zoom_results As String = proc.StandardOutput.ReadToEnd
' read from stdout
' Print the output

If you encounter encoding problems with UTF-8, see the troubleshooting section above.

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

Please see this other FAQ, "How do I create a search form on ASPX pages?" on the Troubleshooting ASP.NET page for more information.

Return to the Zoom Search Engine Support page