404.aspx
上传用户:huiyue
上传日期:2022-04-08
资源大小:1429k
文件大小:3k
源码类别:

搜索引擎

开发平台:

ASP/ASPX

  1. <%@ Page Language="C#" AutoEventWireup="true"  Buffer="false" %>
  2. <script runat="server">
  3.     /// <summary>
  4.     /// Handles 404 (File Not Found) to emit KML for Google Earth to display [v6]
  5.     /// </summary>
  6.     /// <remarks>
  7.     /// Whether the original (not found) url is in the aspxerrorpath OR x-rewrite-url 
  8.     /// depends on how the custom error handling is setup: in IIS5/6 via the Custom Errors
  9.     /// Tab, or in Cassini/IIS7 via web.config (at least, I think that's how they differ)
  10.     /// </remarks>
  11.     public void Page_Load()
  12.     {
  13.         string qs = Request.QueryString["aspxerrorpath"]; // if 404 set in web.config
  14.         if (qs == null)
  15.         {
  16.             qs = Request.Headers["X-REWRITE-URL"]; // if 404 set to URL /404.aspx in IIS5
  17.         }
  18.         if (qs.ToLower().StartsWith("/searchkml/"))
  19.         {
  20.             if (qs.ToLower().EndsWith(".kml"))
  21.             {   // extract the actual search query
  22.                 string q = qs.Substring("/SearchKml/".Length, qs.Length - "/SearchKml/".Length - ".kml".Length);
  23.                 Response.BufferOutput = false;
  24.                 Response.StatusCode = 200;
  25.                 Response.StatusDescription = "OK";
  26.                 Response.ContentType = "application/vnd.google-earth.kml+xml";
  27.                 Response.AddHeader("content-disposition", "attachment; filename=" + q + ".kml");
  28.                 // execute the query using the SearchKml.aspx page
  29.                 Server.Execute("/SearchKml.aspx?searchfor=" + q);
  30.                 Response.End();
  31.             }
  32.         }
  33.         if (qs.ToLower().StartsWith("/searchjson/"))
  34.         {
  35.             if (qs.ToLower().EndsWith(".js"))
  36.             {   // extract the actual search query
  37.                 string q = qs.Substring("/SearchJson/".Length, qs.Length - "/SearchJson/".Length - ".js".Length);
  38.                 Response.BufferOutput = false;
  39.                 Response.StatusCode = 200;
  40.                 Response.StatusDescription = "OK";
  41.                 Response.ContentType = "text/javascript";
  42.                 //Response.AddHeader("content-disposition", "attachment; filename=" + q + ".kml");
  43.                 // execute the query using the SearchKml.aspx page
  44.                 Server.Execute("/SearchJson.aspx?searchfor=" + q);
  45.                 Response.End();
  46.             }
  47.         }
  48.         Response.StatusCode = 404;
  49.         // otherwise the basic '404' message below gets written to the browser
  50.     }
  51. </script>
  52. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  53. <html xmlns="http://www.w3.org/1999/xhtml" >
  54. <head runat="server">
  55.     <title>404</title>
  56.     <meta name="description" http-equiv="description" content="The page could not be found." />
  57.     <meta name="robots" http-equiv="robots" content="noindex,nofollow" />
  58. </head>
  59. <body>
  60.     <div>
  61.         404 - Page not found
  62.     </div>
  63. </body>
  64. </html>