2017-05-25 78 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

好的,非常感谢,我会尽力而为 –