当前位置: 移动技术网 > IT编程>开发语言>c# > C#运行CGI程序实例

C#运行CGI程序实例

2019年07月18日  | 移动技术网IT编程  | 我要评论
本文实例讲述了c#运行cgi程序的方法。分享给大家供大家参考。具体实现方法如下: 一、控制面板—>程序和功能—>打开或关闭windows功能 把相关的功能勾

本文实例讲述了c#运行cgi程序的方法。分享给大家供大家参考。具体实现方法如下:

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

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

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

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

复制代码 代码如下:
using system;
using system.collections.generic;
using system.text;
using system.threading;

namespace cgi
{
    class program
    {
        static int i = 0;

        static void main(string[] args)
        {
            thread thread = new thread(new parameterizedthreadstart(delegate(object obj)
            {
                while (true)
                {
                    if (i < 100)
                    {
                        i++;
                        thread.sleep(100);
                    }
                    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(0);
                    }
                }
            }));
            thread.start();
        } // end of main
    } // end of program
}

四、web程序页面代码:

复制代码 代码如下:
<%@ page language="c#" autoeventwireup="true" codebehind="cgitest.aspx.cs" inherits="web监听.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></title>
    <link href="/js/easyui/easyui.css" rel="stylesheet" type="text/css" />
    <script src="/js/jquery.min.js" type="text/javascript"></script>
    <script src="/js/easyui/jquery.easyui.min.js" type="text/javascript"></script>
    <script src="/js/simpowindow.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            $.ajax({
                type: "get",
                url: "http://localhost:160/cgi.exe?data=abcd",
                datatype: "json",
                error: function (xmlhttprequest, textstatus, errorthrown) {
                    $("#msg").html(textstatus);
                },
                success: function (data, textstatus) {
                    $("#msg").html(data.d);
                }
            });

            //倒计时
            updatetime(10);
        });

        //倒计时
        function updatetime(n) {
            if ($("#msg").html().indexof("请等待") != -1) {
                $("#msg").html("请等待(" + n + ")......");

                if (n > 0) {
                    settimeout(function () {
                        updatetime(n - 1);
                    }, 1000);
                }
            }
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div id="msg" style="text-align: center; vertical-align: middle;">
        请等待......
    </div>
    </form>
</body>
</html>

希望本文所述对大家的c#程序设计有所帮助。

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网