Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在Asp.Net网站中执行C代码_C#_Asp.net - Fatal编程技术网

C# 如何在Asp.Net网站中执行C代码

C# 如何在Asp.Net网站中执行C代码,c#,asp.net,C#,Asp.net,我是C.NET的新手。 我想知道如何在.aspx网站中执行.cs程序。单击 假设我想在按钮单击中执行以下代码 using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication3 { class Program { static void Main(string[] args) { int a = 10

我是C.NET的新手。 我想知道如何在.aspx网站中执行.cs程序。单击

假设我想在按钮单击中执行以下代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication3
{
class Program
{
    static void Main(string[] args)
    {
        int a = 10;
        int b = 20;
        int c = a + b;

        Console.WriteLine(c);
        Console.ReadKey();

    }
}
}
还有按钮-

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{

}
}

Microsoft不建议从Web应用程序调用.exe,因为出于安全原因,w3wp.exe在沙盒环境中运行,因此它启动的任何线程/任务/进程都与您自己启动时的线程/任务/进程不同,因此可能无法按预期工作


是,但不推荐。

欢迎使用。您可以选择将程序导出为Nuget包,然后在.aspx按钮事件中调用相应的方法,这是一种方法。将代码从该主按钮移动到按钮1\u单击。但你不能使用控制台!