简体   繁体   English

将PHP与asp.net / asp.net-mvc集成的最佳方法

[英]Best way to integrate PHP with asp.net / asp.net-mvc

By some coincidence this problem has come up twice in the last week. 碰巧的是,这个问题在上周两次出现。

A customer has an existing PHP web site which they want to keep. 客户拥有要保留的现有PHP网站。 They also have or will soon have some ASP.net web pages that they wish to integrate into the existing site, in a way that it appears as a single site. 他们还拥有或即将拥有一些ASP.net网页,希望将它们集成到现有站点中,以使其显示为单个站点。

We have though of the following possibilities: 但是,我们有以下几种可能性:

  • Use IFrame 使用iframe
  • Copy all html / menus to the new site and link between sites, user moves between sites but does not notice, if he does not look at the url 将所有html /菜单复制到新站点并在站点之间链接,如果用户未查看url,则用户在站点之间移动但没有注意到
  • Use web services to read information from the asp.net web site and write the html on the PHP site. 使用Web服务从asp.net网站读取信息,并在PHP网站上编写html。
  • Use WSRP (Web services Remote Portlets). 使用WSRP(Web服务远程Portlet)。 Have tested this to display Sharepoint webparts on a Java site, have not tested with PHP. 已对此进行测试以在Java站点上显示Sharepoint Webpart,但尚未与PHP进行测试。

Has anyone tried any of these? 有人尝试过这些吗? Has a better suggestion? 有更好的建议吗? Is there any we should definatly avoid? 有什么我们应该绝对避免的吗?

Thanks 谢谢

Shiraz 西拉

It really depends on what an acceptable level of integration is. 这实际上取决于可接受的集成水平。 Your original suggestions have a number of issues with maintainability, and I would not suggest they are used for an public-facing internet site. 您最初的建议在可维护性方面存在许多问题,我不建议将其用于面向公众的互联网站点。

If I had full control, I might consider migrating the PHP site to IIS, and deploying ASP.NET pages to the site alongside the PHP files. 如果可以完全控制,我可能会考虑将PHP网站迁移到IIS,并将ASP.NET页面与PHP文件一起部署到该网站。 This can be quite tricky depending on how the PHP site has been built. 根据PHP网站的构建方式,这可能非常棘手。 Problems you might run into including: 您可能会遇到的问题包括:

  • Use of mod_rewrite in the PHP app and whether you have a suitable replacement on Windows. 在PHP应用程序中使用mod_rewrite,以及在Windows上是否有合适的替代品。 This situation is a lot better at the time of writing but you might need to debug the existing configuration. 在编写本文时,这种情况要好得多,但是您可能需要调试现有配置。
  • Extensions. 扩展。 Are all of the PHP libraries and extensions you need available on Windows? Windows上是否提供了您需要的所有PHP库和扩展?
  • Performance. 性能。 Some people have reported unacceptable performance of PHP under Windows. 有人报告Windows下PHP的性能不可接受。 I'm sure with the right performance tuning you can deliver something equivalent to your old site, if this is even an issue. 我相信通过正确的性能调整,即使这是一个问题,您也可以提供与您的旧站点相同的功能。

On your suggested options 在您建议的选项上

  • Use IFrame . 使用IFrame This is workable but a little clunky, It may turn out to be problematic if you need things like SSL or JavaScript interactivity between the code bases. 这是可行的,但有点笨拙,如果您需要代码库之间的SSL或JavaScript交互之类的东西,可能会出现问题。
  • Link between sites . 站点之间的链接 This is workable, but there could be issues if SEO is important to you. 这是可行的,但如果SEO对您很重要,则可能会出现问题。 Sometimes there are more links than just menus that you need to consider too. 有时,除了菜单之外,您还需要考虑更多的链接。
  • Use web services to read the ASP.NET pages . 使用Web服务读取ASP.NET页 This is only really feasible if you have very simple pages that have zero interactions or postbacks. 仅当您具有非常简单的页面且交互或回传为零时,这才真正可行。 If you need to handle postbacks, viewstate etc you are going to be in trouble. 如果您需要处理回发,viewstate等问题,将会遇到麻烦。 Using ASP.NET MVC gives you more control and an easier experience integrating this way. 使用ASP.NET MVC可以为您提供更多控制权,并且可以更轻松地集成这种方式。 My personal opinion is that it is extremely hacky and only something I would do for a single page (if it was really important). 我个人的观点是,它非常hacky,只有我可以在单个页面上执行某些操作(如果它真的很重要)。
  • Use WSRP (Web services Remote Portlets) . 使用WSRP(Web服务远程Portlet) I'm not sure that this is an option with regular ASP.NET, I always thought this was an additional feature with SharePoint. 我不确定这是常规ASP.NET的选项,我一直认为这是SharePoint的附加功能。

All these options are completely overboard! 所有这些选择都太过分了!

Simple solution would be to keep the solutions hosted seperately, Apache & IIS respectively. 一个简单的解决方案是将解决方案分别托管在Apache和IIS中。 And handle the integration Via Routing. 并通过路由处理集成。 The authentication could be handled by using the "Cookie" 可以使用“ Cookie”来处理身份验证

We've handled this recently for a customer with no issues 我们最近为没有问题的客户处理了此问题

The web front end was based on wordpress & mySQL and an entire reporting module was MVC 3/4 based on SQL server 2008 r2 based. Web前端基于wordpress和mySQL,整个报告模块是基于SQL Server 2008 r2的MVC 3/4。

We just used sub domains .ie www.somecompany.com for website and reports.somecompany.com for the reports. 我们仅将子域名.ie www.somecompany.com用于网站,将reports.somecompany.com用于报告。

We then just wrote a simple wordpress extension, to store linking data to which contained relevant information to create reports. 然后,我们只是编写了一个简单的wordpress扩展名,用于存储包含相关信息的链接数据以创建报告。 ie Guid ID of user and report type etc. 即用户的Guid ID和报告类型等。

Which essentially just presented the User with a page containing some reports options they could run - hyperlinks <a href="http://reports.somecompanyurl.com/bill/{some guid}>You Monthly Bill</a> 实际上,这实际上只是向用户显示了一个页面,其中包含一些可以运行的报告选项-超链接<a href="http://reports.somecompanyurl.com/bill/{some guid}>You Monthly Bill</a>

ie Monthly Bill 即每月帐单

Both sites shared a common theme, which does carry some maintenance burden, but no more than a usual web project. 这两个站点共享一个共同的主题,这确实带来了一定的维护负担,但是只不过是一个普通的Web项目而已。 ie.. MVC and PHP theme files do have some differences, but in general the CSS files were the same. 即.. MVC和PHP主题文件确实有一些区别,但是通常CSS文件是相同的。

I think we did customize the cookie a bit, but this wasn't really any hardship, as both solutions just used the same cookie name and cookie encryption. 我认为我们确实对cookie进行了一些自定义,但这并不是什么难事,因为两种解决方案都使用相同的cookie名称和cookie加密。

On the whole it was a fairly painless integration project, as most communication was handled via routing. 总体而言,这是一个相当轻松的集成项目,因为大多数通信都是通过路由进行的。

we've been running this for 6 months without any issues. 我们已经运行了6个月,没有任何问题。

Can the entire site be hosted on a windows machine running IIS? 可以将整个站点托管在运行IIS的Windows计算机上吗? Because IIS can serve PHP pages as well as asp.net. 因为IIS可以提供​​PHP页面以及asp.net。 That way you can mix-and-match the pages together, seamlessly. 这样,您可以无缝地将页面混合和匹配在一起。

Another, more "dirty" option would be to use PHP to "read" the HTML output from the remote asp.net pages directly. 另一个更“肮脏”的选择是使用PHP直接从远程asp.net页“读取” HTML输出。 You would have one PHP file for each corresponding asp.net page and then you could "read" it via HTTP using PHP's file_get_contents method: 每个对应的asp.net页都有一个PHP文件,然后可以使用PHP的file_get_contents方法通过HTTP“读取”它:

$content = file_get_contents('http://www.example.com/remotepage.aspx');

You'd probably want to cache the results locally to improve efficiency. 您可能希望将结果缓存在本地以提高效率。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM