[英]Is it possible to run php code at asp.net with c#
在后台使用 c# 时,是否可以在 asp.net 中使用一些 php 代码。
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="MeineWebseite.löschen.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<?php
echo "Hallo \"Welt\"";
echo $name;
echo " - i'am feeling fine";
function ausgabe ($wert)
{
echo $wert;
}
?>
</form>
</body>
</html>
我想像这样使用php。 我应该安装哪个包?
就在IIS
下运行PHP
项目而言,这是可以实现的,这里有一个关于 SO 的答案,可能在这方面有所帮助。
但是,如果您想混合使用 ASP.NET C# 和 PHP 代码,那么我认为这是不可能的。 真正的问题是,你到底为什么要走这条路? 有什么 PHP 可以做而 C# 不能做的事情? 对我来说,C# 似乎比 PHP 更优雅,你为什么要这样做呢?
就能够在前端回显一些数据而言,您可以像这样在 C# 中做到这一点(或使用许多其他可能适合您的场景的方式):
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="MeineWebseite.löschen.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:Literal runat="server" ID="ltEchos"/> <!-- Would share a sample to use this control to populate things -->
</form>
</body>
</html>
.CS
代码背后:
public void EchoSomeDataWithResponseWrite()
{
Response.Write("Hallo \"Welt\""); // echo, that does not involves the Literal control
// to give a line break, put your html like below
Response.Write("<br />");
var name = "John Doe"; // to write name
Response.Write(name);
// to write some raw script:
Response.Write("<script>alert('Weather is fine today!')</script>");
}
public void EchoSomeDataWithLiteralControl()
{
var name = "John Doe";
var html = "Hallo \"Welt\" <br /> ";
html += name + "<br />";
ltEchose.Text = html;
}
力量在你手中,你可以使用 C# 实现任何你可以使用 PHP 实现的东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.