2009-10-27 41 views
1

好日子讓PHP輸出

,我們使用的是C#MVC的網頁的工作,我們在取得PHP輸出到顯示器上的MVC網頁的製作。我們在php中創建了1個頁面,文件名爲「hello.php」,它顯示「hello word」

我們已經將調用頁面的代碼放在usercontrol中,但是當它放在site.master廣告運行中時它給我們hello.php而不是「你好世界的代碼。

我們的用戶控件的代碼如下

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

希望任何人的響應

回答

1

你實際上是打開PHP頁面作爲物理文件在服務器上,因此你在列表中PHP頁面作爲普通的舊文本文件。

您將需要使用HttpWebRequest獲得頁面的內容,因爲它會出現在瀏覽器上。

here

1

爲了讓PHP輸出,你必須執行PHP腳本,沒有看過。你現在正在做的就是用記事本打開PHP文件並獲取它的輸出。

這裏是how to execute PHP from C#好的帖子 - 我認爲這是一個很好的例子的地方開始。