1

good day

we are working on mvc webpage using c# and we are on the making of a getting php output to display on a mvc webpage. we have 1 page created in php with the filename "hello.php" and it displays "hello word"

we have place the code for calling the page in a usercontrol, but when place it in the site.master ad run it gives us the code of hello.php and not the "hello world.

our usercontrol code is as follows

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl"  %>

<%@ Import Namespace="System.IO" %> 
<script runat="server">

    protected void Page_Load(object sender, EventArgs e)
    {
        string file = Server.MapPath("Hello.php");
        StreamReader sr;
        FileInfo fi = new FileInfo(file);
        string input = "";
        if (File.Exists(file))
        {
            sr = File.OpenText(file);
            input += Server.HtmlEncode(sr.ReadToEnd());
            sr.Close();
        }
        Response.Write(input);

    }
</script>

hope for anyone's response

2 Answers 2

1

You are actually opening the PHP page as a physical file on the server, therefore you are listing the PHP page as a plain old text file.

You will need to use the HttpWebRequest to get the contents of the page as it would appear on the browser.

See here

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

Comments

1

In order to get php output you have to execute the php script, not read it. What you're doing right now is sort of equivalent to opening the PHP file with Notepad and getting its outputs.

Here is a good post on how to execute PHP from C# - I think it's a good example place to start with.

Comments

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.