c# - 我如何在 Asp .Net 网站中执行 C# 代码
问题描述
我是 C# .NET 的新手。我想知道如何在 .aspx 网站 buttonClick 中执行 .cs 程序。
假设我想在 buttonclick 中执行以下代码。
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 在沙盒环境中运行,因此它启动的任何线程/任务/进程都与您自己启动时不同,因此可能无法按预期工作。
是可能的,但不推荐。
推荐阅读
- live-connect-sdk - 如何将connectSDK库添加到android studio
- asp.net - 将 [Authorize] 与 [Route("xyz")] 一起使用时的无限循环
- google-apps-script - 如何在文件启动(onOpen)时直接启动 HtmlService?
- python-2.7 - 上传到服务器的图像文件损坏/不支持格式;蟒蛇,cgi和html
- generics - Groovy @CompileStatic 与有界泛型
- spring-boot - 具有多个模块的 Spring Boot 项目的集中控制台着色
- ios - 将数据传递给 Swift 中的选择器
- php - 将整个动态页面放入 If 语句的正确方法
- javascript - 如何有条件地使用内置的 Node.js 或带有 ES6 样式导入的浏览器 API 方法?
- python - 如何使用自定义分隔符和键值对解析文本列表