-1

Is it possible to use some php code in asp.net while using c# in background.

<%@ 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>

I would like to use php like this way. Which package should I install?

4
  • Did you try it? Commented Feb 9, 2020 at 21:38
  • yes, I did it! I tried to use peachpie, but it didnt work so like I want Commented Feb 9, 2020 at 21:43
  • You cannot just mix two languages. For starters, pick one language and learn how to write simple programs with it. After a while, you may look at other languages and then see the pros and cons of each of them. Commented Feb 9, 2020 at 23:59
  • ok! I understand it now. Thank you Commented Feb 10, 2020 at 22:50

1 Answer 1

0

As far as it is concerned running PHP projects under IIS, it is possible to achieve, here is an answer on SO that might help in this regard.

But if you want to mix up ASP.NET C# and PHP code then I suppose it is not possible. The real question is, why on earth would you want to go this way? Is there something PHP can do and C# cannot? To me, C# seems way more elegant than PHP, why would you want to do it anyway?

As far as it is concerned being able to echo some data on front-end you can do that in C# like this (or using many other ways that might suit your scenario):

<%@ 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 Code Behind:

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;
}

Power is in your hand, you can achieve anything using C# that you could've achieved using PHP.

Sign up to request clarification or add additional context in comments.

2 Comments

Many people nowerdays use PHP and its easy to use it sofar I know. Until now Ive worked with c# but I tried to display images form folder randomly but I couldnt do it, but I saw in internet many examples with PHP
You can find many examples to display images using C# as well. There is way lot of helping material over the world wide web.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.