C#運(yùn)行CGI程序?qū)嵗?/h1>
更新時(shí)間:2014年12月01日 16:17:18 投稿:shichen2014
這篇文章主要介紹了C#運(yùn)行CGI程序的方法,實(shí)例講述了具體的配置步驟與實(shí)現(xiàn)代碼,具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
本文實(shí)例講述了C#運(yùn)行CGI程序的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:
一、控制面板—>程序和功能—>打開或關(guān)閉Windows功能
把相關(guān)的功能勾上,點(diǎn)“確定”

二、新建一個(gè)網(wǎng)站,配置ISAPI和CGI限制、處理程序映射


三、CGI控制臺(tái)應(yīng)用程序代碼:
復(fù)制代碼 代碼如下: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\":\"您傳入的參數(shù)為:" + keyValue[1] + ",輸出結(jié)果為:" + i + "\"}");
Environment.Exit(0);
}
}
}));
thread.Start();
} // end of Main
} // end of Program
}
四、Web程序頁(yè)面代碼:
復(fù)制代碼 代碼如下:<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CGITest.aspx.cs" Inherits="Web監(jiān)聽.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);
}
});
//倒計(jì)時(shí)
UpdateTime(10);
});
//倒計(jì)時(shí)
function UpdateTime(n) {
if ($("#msg").html().indexOf("請(qǐng)等待") != -1) {
$("#msg").html("請(qǐng)等待(" + 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;">
請(qǐng)等待......
</div>
</form>
</body>
</html>
希望本文所述對(duì)大家的C#程序設(shè)計(jì)有所幫助。
您可能感興趣的文章:- C#默認(rèn)以管理員身份運(yùn)行程序?qū)崿F(xiàn)代碼
- c#異步操作后臺(tái)運(yùn)行(backgroundworker類)示例
- C#實(shí)現(xiàn)只運(yùn)行單個(gè)實(shí)例應(yīng)用程序的方法(使用VB.Net的IsSingleInstance)
- C#在運(yùn)行時(shí)動(dòng)態(tài)創(chuàng)建類型的實(shí)現(xiàn)方法
- C#判斷某程序是否運(yùn)行的方法
- 在Linux上運(yùn)行C#的方法
- C#實(shí)現(xiàn)軟件監(jiān)控外部程序運(yùn)行狀態(tài)的方法
- c#通過app.manifest使程序以管理員身份運(yùn)行
- C#隱式運(yùn)行CMD命令(隱藏命令窗口)
- C#實(shí)現(xiàn)將程序運(yùn)行信息寫入日志的方法
- C#運(yùn)行時(shí)相互關(guān)系淺析
相關(guān)文章
-
WPF利用RichTextBox實(shí)現(xiàn)富文本編輯器
在實(shí)際應(yīng)用中,富文本隨處可見,那么在WPF開發(fā)中,如何實(shí)現(xiàn)富文本編輯呢?本文以一個(gè)簡(jiǎn)單的小例子,簡(jiǎn)述如何通過RichTextBox實(shí)現(xiàn)富文本編輯功能,需要的可以參考下 2024-02-02
-
c#打印預(yù)覽控件中實(shí)現(xiàn)用鼠標(biāo)移動(dòng)頁(yè)面功能代碼分享
項(xiàng)目中需要實(shí)現(xiàn)以下功能:打印預(yù)覽控件中,可以用鼠標(biāo)拖動(dòng)頁(yè)面,以查看超出顯示范圍之外的部分內(nèi)容,下面就是實(shí)現(xiàn)代碼 2013-12-12
-
C# DataGridView中實(shí)現(xiàn)勾選存儲(chǔ)數(shù)據(jù)和右鍵刪除數(shù)據(jù)(示例代碼)
這篇文章主要介紹了C# DataGridView中實(shí)現(xiàn)勾選存儲(chǔ)數(shù)據(jù)和右鍵刪除數(shù)據(jù)的示例代碼,通過示例代碼給大家展示運(yùn)行效果圖,需要的朋友可以參考下 2021-07-07
-
HTML文本框的值改變后觸發(fā)后臺(tái)代碼的方法
asp.net用日期插件,當(dāng)選中一個(gè)日期時(shí)觸發(fā)一個(gè)事件,以查詢當(dāng)前日期的數(shù)據(jù)。這是要跟數(shù)據(jù)庫(kù)交互的。先貼出控件代碼: 2013-04-04
-
C#解析char型指針?biāo)赶虻膬?nèi)容(實(shí)例解析)
在c++代碼中定義了一個(gè)功能函數(shù),這個(gè)功能函數(shù)會(huì)將計(jì)算的結(jié)果寫入一個(gè)字符串型的數(shù)組中output,然后c#會(huì)調(diào)用c++導(dǎo)出的dll中的接口函數(shù),然后獲取這個(gè)output并解析成string類型,本文通過實(shí)例解析C#?char型指針?biāo)赶虻膬?nèi)容,感興趣的朋友一起看看吧 2024-03-03
-
Netcore?Webapi返回?cái)?shù)據(jù)的三種方式示例
這篇文章主要為大家介紹了Netcore?Webapi返回?cái)?shù)據(jù)的三種方式示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪 2022-09-09
最新評(píng)論
本文實(shí)例講述了C#運(yùn)行CGI程序的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:
一、控制面板—>程序和功能—>打開或關(guān)閉Windows功能
把相關(guān)的功能勾上,點(diǎn)“確定”
二、新建一個(gè)網(wǎng)站,配置ISAPI和CGI限制、處理程序映射
三、CGI控制臺(tái)應(yīng)用程序代碼:
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\":\"您傳入的參數(shù)為:" + keyValue[1] + ",輸出結(jié)果為:" + i + "\"}");
Environment.Exit(0);
}
}
}));
thread.Start();
} // end of Main
} // end of Program
}
四、Web程序頁(yè)面代碼:
<!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);
}
});
//倒計(jì)時(shí)
UpdateTime(10);
});
//倒計(jì)時(shí)
function UpdateTime(n) {
if ($("#msg").html().indexOf("請(qǐng)等待") != -1) {
$("#msg").html("請(qǐng)等待(" + 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;">
請(qǐng)等待......
</div>
</form>
</body>
</html>
希望本文所述對(duì)大家的C#程序設(shè)計(jì)有所幫助。
- C#默認(rèn)以管理員身份運(yùn)行程序?qū)崿F(xiàn)代碼
- c#異步操作后臺(tái)運(yùn)行(backgroundworker類)示例
- C#實(shí)現(xiàn)只運(yùn)行單個(gè)實(shí)例應(yīng)用程序的方法(使用VB.Net的IsSingleInstance)
- C#在運(yùn)行時(shí)動(dòng)態(tài)創(chuàng)建類型的實(shí)現(xiàn)方法
- C#判斷某程序是否運(yùn)行的方法
- 在Linux上運(yùn)行C#的方法
- C#實(shí)現(xiàn)軟件監(jiān)控外部程序運(yùn)行狀態(tài)的方法
- c#通過app.manifest使程序以管理員身份運(yùn)行
- C#隱式運(yùn)行CMD命令(隱藏命令窗口)
- C#實(shí)現(xiàn)將程序運(yùn)行信息寫入日志的方法
- C#運(yùn)行時(shí)相互關(guān)系淺析
相關(guān)文章
WPF利用RichTextBox實(shí)現(xiàn)富文本編輯器
在實(shí)際應(yīng)用中,富文本隨處可見,那么在WPF開發(fā)中,如何實(shí)現(xiàn)富文本編輯呢?本文以一個(gè)簡(jiǎn)單的小例子,簡(jiǎn)述如何通過RichTextBox實(shí)現(xiàn)富文本編輯功能,需要的可以參考下2024-02-02c#打印預(yù)覽控件中實(shí)現(xiàn)用鼠標(biāo)移動(dòng)頁(yè)面功能代碼分享
項(xiàng)目中需要實(shí)現(xiàn)以下功能:打印預(yù)覽控件中,可以用鼠標(biāo)拖動(dòng)頁(yè)面,以查看超出顯示范圍之外的部分內(nèi)容,下面就是實(shí)現(xiàn)代碼2013-12-12C# DataGridView中實(shí)現(xiàn)勾選存儲(chǔ)數(shù)據(jù)和右鍵刪除數(shù)據(jù)(示例代碼)
這篇文章主要介紹了C# DataGridView中實(shí)現(xiàn)勾選存儲(chǔ)數(shù)據(jù)和右鍵刪除數(shù)據(jù)的示例代碼,通過示例代碼給大家展示運(yùn)行效果圖,需要的朋友可以參考下2021-07-07HTML文本框的值改變后觸發(fā)后臺(tái)代碼的方法
asp.net用日期插件,當(dāng)選中一個(gè)日期時(shí)觸發(fā)一個(gè)事件,以查詢當(dāng)前日期的數(shù)據(jù)。這是要跟數(shù)據(jù)庫(kù)交互的。先貼出控件代碼:2013-04-04C#解析char型指針?biāo)赶虻膬?nèi)容(實(shí)例解析)
在c++代碼中定義了一個(gè)功能函數(shù),這個(gè)功能函數(shù)會(huì)將計(jì)算的結(jié)果寫入一個(gè)字符串型的數(shù)組中output,然后c#會(huì)調(diào)用c++導(dǎo)出的dll中的接口函數(shù),然后獲取這個(gè)output并解析成string類型,本文通過實(shí)例解析C#?char型指針?biāo)赶虻膬?nèi)容,感興趣的朋友一起看看吧2024-03-03Netcore?Webapi返回?cái)?shù)據(jù)的三種方式示例
這篇文章主要為大家介紹了Netcore?Webapi返回?cái)?shù)據(jù)的三種方式示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-09-09