微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐