当从activex / classic asp / spel代码调用C#exe时,irestresponse响应返回状态0(CA服务器端代码)

时间:2018-06-14 14:13:18

标签: c# asp.net ajax restsharp

我有一个带有c#.net命令代码的EXE文件,.net上的代码工作得很好但是当我使用activexobject / classic asp / spel代码(CA服务器端代码)运行exe时,它输入exe(我知道)因为它几乎每一步都写入日志文件)但是当它到达REST部分时它返回0。 当我在.NET中运行代码或从CMD手动运行服务器中的exe文件时,它运行良好,我可以在日志文件中看到irestResponse。

.net代码:

using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Configuration;
using System.Linq;
using System.Text;
using RestSharp;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using System.IO;
using Newtonsoft.Json;
using Newtonsoft.Json.Bson;
using Newtonsoft.Json.Serialization;
using Newtonsoft.Json.Schema;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Utilities;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Linq.JsonPath;
using System.Windows.Input;
using System.Net.Http;
using log4net;
using RestSharp.Deserializers;
using System.Xml;
using System.Web;
using System.Diagnostics;





namespace igi
{
    class Program
    {
        public static void Main(string[] args)
        {
            var userid = "D641139";
            var userigiID = "275";
            var token = "";
            string responseString = "";
            var workFlowId = "";
            string responseString6 = "";

            //get LOG directory

            string log_work_directory = ConfigurationManager.AppSettings["LogDirectory"];

            //Create LOG file

            string file_date_name = DateTime.Now.ToString("yyyyMMdd_HHmmss");
            TextWriter tw = new StreamWriter(log_work_directory + "Global_Log_" + file_date_name + ".txt");
            tw.WriteLine(DateTime.Now.ToString() + "\tStart");
            //tw.WriteLine(args[0] + " " + args[1]);

            System.Diagnostics.Process process = new System.Diagnostics.Process();

            System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();

            startInfo.FileName = "cmd.exe";
            startInfo.Arguments = "/c whoami";
            process.StartInfo = startInfo;
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.UseShellExecute = false;
            process.Start();
            process.WaitForExit();
            tw.WriteLine(process.StandardOutput.ReadToEnd());

            //ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(AcceptAllCertificates);

            //ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls;



            try
            {
                /////////////////////////////////////////////////login - start//////////////////////////////////////

                var client = new RestClient("https://server:9343/igi/v2/security/login");

                var request = new RestRequest(Method.GET);
                request.AddHeader("Accept", "text/plain");
                //request.AddHeader("postman-token", "6698c824-d7ab-3089-b6eb-9d30ebab4839");
                request.AddHeader("cache-control", "no-cache");
                request.AddHeader("Authorization", "Basic c2RtYWRtaW46c2RtYWRtaW4=");
                request.AddHeader("realm", "ideas");
                //request.AddHeader("Content-Type", "text/plain");
                request.AddHeader("Content-Type", "application/scim+json; chartset=utf-8");
                request.AddParameter("application/scim+json; chartset=utf-8", ParameterType.RequestBody);

                tw.WriteLine(DateTime.Now.ToString() + "\t login token request - " + request);

                IRestResponse response = client.Execute(request);

                var token2 = response.StatusCode.ToString();

                tw.WriteLine(DateTime.Now.ToString() + "\t login token response - " + token2);

                token = response.Content;

                tw.WriteLine(DateTime.Now.ToString() + "\t login token - " + token);

                /////////////////////////////////////////////////login - end//////////////////////////////////////
            }
            catch(Exception log)
            {
                tw.WriteLine(DateTime.Now.ToString() + "\t login faild - " + log);
                tw.Close();
                return;
            }
      }
   }
}

这是对exe的activex调用:

function igi()
{
var objShell = new ActiveXObject("WScript.Shell");
objShell.run("d:\\IGI\\igi.exe");
}

这是经典的asp调用和asp中调用exe的代码:

function igiasp()
{
var sResult = GetXmlResponse_("", "$CAisd/sitemods/asp/igi.asp");
}

<script language=javascript runat=server>
                Response.Expires =-1;
                Response.CharSet =1;
                Response.CodePage=65001;
                var table   = new String(Request.QueryString("table"));
                var sh =Server.CreateObject("WScript.Shell");  
                var re = sh.run("D:\\IGI\\cmd.exe.lnk",1 , true);
                Response.Write(re);
</script>

另一个重要的事情,当我使用JQuery从html页面上的ajax调用相同的REST时,它很适合:

function loginIgi() {
jq.ajax(
{
async: true,
crossDomain: true,                   
type: "GET",
dataType: "json",
headers: {"Accept":"text/plain","Authorization":"Basic c2RtYWRtaW46c2RtYWRtaW4=","realm":"ideas"},
url: "https://server:9343/igi/v2/security/login",
complete: function(resp) {                                                                if(resp.responseText!= ''){//return json value
GetWfIgi(resp.responseText);       
var jsn = JSON.parse(resp.responseText);                                                                                try {                                                                                                                                      var aa = isnull(jsn[0].id, '').toUpperCase();                                                                                                                                                                                                                                                                           }                                                                                                                                                                             catch(err) {                                                                               }

                                                            }

                                            }

                            })
}

**正如你在.net文件中看到的那样,我检查运行exe soo的用户我尝试了各种类型的用户(本地用户,本地服务器,域用户),并且都具有相同的结果。

请帮忙! TNX

0 个答案:

没有答案