PassMark Logo
Home » Forum

Announcement

Collapse
No announcement yet.

Encoding fix for .NET/cgi method

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Encoding fix for .NET/cgi method

    My company uses Zoom search for our recently-updated website, which runs on .NET 2.0. I used the method outlined on the Wrensoft site for running the cgi process and retrieving the search results, which works very well, but I ran into a problem with character sets. Non-standard characters like angled quotation marks and large dashes weren't decoding properly in the search result context, and changing the encoding in Zoom wasn't helping.

    I realized that it might be a problem further down in the pipe, and came up with the following fix:

    Code:
    <%@ Import Namespace="System.IO" %>
    <%@ Import Namespace="System.Diagnostics" %>
    <%@ Import Namespace="System.Text" %>
    <%@ 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.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();
    
    byte[] bytes = proc.StandardOutput.CurrentEncoding.GetBytes(zoom_results);
    
    // Print the output
    Response.Write(Encoding.UTF8.GetString(bytes));
    %>
    Notice the last two lines with the byte array and the Encoding. When I set the Zoom codepage to UTF-8, this now works perfectly. Don't forget to import System.Text either.

    Enjoy!

  • #2
    Thanks for posting the tip. We actually already have this documented though - it's on our ASP.NET support page, scroll down to the section titled "Troubleshooting":
    http://www.wrensoft.com/zoom/support/aspdotnet.html
    --Ray
    Wrensoft Web Software
    Sydney, Australia
    Zoom Search Engine

    Comment

    Working...
    X