C# · 12月 19, 2021

C# CGI程序

一、控制面板—>程序和功能—>打开或关闭Windows功能

    把相关的功能勾上,点“确定”

二、新建一个网站,配置ISAPI和CGI限制、处理程序映射

三、CGI控制台应用程序代码:

using System; System.Collections.Generic; System.Text; System.Threading;namespace CGI{ class Program { static int i = 0; void Main(string[] args) { Thread thread = new Thread(new ParameterizedThreadStart(delegate(object obj) { while (true) { if (i < 100) { i++; Thread.Sleep(); } else { string queryStr = Environment.GetEnvironmentVariable(“QUERY_STRING”); string[] paramArr = queryStr.Split(‘&’string[] keyValue = paramArr[0].Split(=); Console.Write(Content-Type: text/html;charset=GB2312;\n\n); Console.Write({\”d\”:\”您传入的参数为:” + keyValue[1] + ,输出结果为:” + i + \”}); Environment.Exit(); } } })); thread.Start(); } // end of Main } end of Program}View Code

四、Web程序页面代码:

<%@ Page Language=”C# AutoEventWireuptrue CodeBehindCGITest.aspx.cs InheritsWeb监听.CGITest” %><!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”><html xmlns=”http://www.w3.org/1999/xhtml”head runat=”server”> title></link href=”/JS/easyui/easyui.css” rel=”stylesheet” type=”text/css” /> script src=”/JS/jquery.min.js”=”text/javascript”script=”/JS/easyui/jquery.easyui.min.js”=”/JS/SimpoWindow.js”type> $(function () { $.ajax({ type: get,url: http://localhost:160/cgi.exe?data=abcdjson (XMLHttpRequest,textStatus,errorThrown) { $(#msg).html(textStatus); },success: (data,textStatus) { $().html(data.d); } }); //倒计时 UpdateTime(10); }); 倒计时 UpdateTime(n) { if ($().html().indexOf(请等待) != -1) { $().html(请等待(” + n + )……); (n > 0) { setTimeout( () { UpdateTime(n – ); },1000); } } } </headbodyform id=”form1″ runatdiv =”msg” style=”text-align: center; vertical-align: middle;”> 请等待…… divformhtml>View Code