2017-05-25 82 views
0

我想要將.net網頁與.net網頁表單集成。 我剛纔複製.PHP網頁,並粘貼到.NET Web應用程序試圖打開.php頁面時點擊asp按鈕

這裏是.NET代碼:

<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /> 

和代碼背後,是

protected void Button1_Click(object sender, EventArgs e) 
{ 
    Server.Transfer("register.php"); 
} 

但它給給定一個異常低於

Server Error in '/' Application. No http handler was found for request type 'POST'

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: No http handler was found for request type 'POST'

Source Error:

Line 17: protected void Button1_Click(object sender, EventArgs e) Line 18: { Line 19:
Server.Transfer("register.php"); Line 20: Line 21:
}

Source File: c:\Users\Vishal\Documents\Visual Studio 2013\Projects\TestHomePage\test3\WebForm2.aspx.cs Line: 19

Stack Trace:

[HttpException (0x80004005): No http handler was found for request type 'POST']
System.Web.HttpApplication.MapIntegratedHttpHandler(HttpContext context, String requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig, Boolean convertNativeStaticFileModule) +898
System.Web.HttpServerUtility.Execute(String path, TextWriter writer, Boolean preserveForm) +464

[HttpException (0x80004005): Error executing child request for register.php.]

回答

0

https://msdn.microsoft.com/en-us/library/caxa892w(v=vs.110).aspx(Server.Transfer文檔):

"The page transferred to should be another .aspx page. For instance, a transfer to an .asp or .asmx page is not valid."

嘗試Response.Redirect("register.php");來代替。這將導致瀏覽器重定向到PHP頁面。你現在正在做的是基本上要求.NET框架執行一些PHP代碼。

此外,您需要確保您已在服務器上安裝了PHP引擎,並且它已全部在IIS中正確註冊,否則PHP頁面將不會執行。

背景:PHP和ASP.NET是兩種完全不同的框架/語言。目前尚不清楚這是否是您的目標,但值得注意的是,您不能期望從一個內部轉移到另一個保存所有會話數據等,他們運行在完全獨立的環境中。正如我所建議的那樣,您可以從一個重定向到另一個,但腳本不會像單個應用程序那樣工作,除非您在幕後做了大量的瑣事。

取決於您獲得多少PHP/.NET,將其中一種語言重寫爲另一種語言以集成它們或者定義一些正式的API以允許它們有序地交換數據可能更容易時尚。

+0

但這兩個項目在相同的解決方案,但在不同的應用程序,每當我使用上面的方法,那麼「頁面找不到」錯誤出現。 –

+0

我給了文件名作爲一個簡單的例子,但如果它不在網站的同一個文件夾中,您需要提供更具體的路徑或完整的URL。找不到頁面就意味着PHP文件不在您指定的位置。我不知道你的IIS結構究竟在哪裏,所以你需要解決這個問題。但原則是一樣的。 – ADyson

+0

好的,非常感謝,我會盡力而爲 –