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

13,107

Solution 1

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. This can be quite tricky depending on how the PHP site has been built. Problems you might run into including:

  • Use of mod_rewrite in the PHP app and whether you have a suitable replacement on 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?
  • Performance. Some people have reported unacceptable performance of PHP under Windows. 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. 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.
  • Link between sites. This is workable, but there could be issues if SEO is important to you. Sometimes there are more links than just menus that you need to consider too.
  • Use web services to read the ASP.NET pages. 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. Using ASP.NET MVC gives you more control and an easier experience integrating this way. My personal opinion is that it is extremely hacky and only something I would do for a single page (if it was really important).
  • Use WSRP (Web services Remote Portlets). I'm not sure that this is an option with regular ASP.NET, I always thought this was an additional feature with SharePoint.

Solution 2

All these options are completely overboard!

Simple solution would be to keep the solutions hosted seperately, Apache & IIS respectively. And handle the integration Via Routing. The authentication could be handled by using the "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.

We just used sub domains .i.e. www.somecompany.com for website and reports.somecompany.com for the reports.

We then just wrote a simple wordpress extension, to store linking data to which contained relevant information to create reports. i.e. Guid ID of user and report type etc.

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>

i.e. Monthly Bill

Both sites shared a common theme, which does carry some maintenance burden, but no more than a usual web project. i.e... MVC and PHP theme files do have some differences, but in general the CSS files were the same.

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.

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.

Solution 3

Can the entire site be hosted on a windows machine running IIS? Because IIS can serve PHP pages as well as 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. 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:

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

You'd probably want to cache the results locally to improve efficiency.

Share:
13,107

Related videos on Youtube

Shiraz Bhaiji
Author by

Shiraz Bhaiji

Architect / dev lead / .net programmer Manager at Evry http://www.evry.no/ Board Member Oslo Software Architecture http://www.meetup.com/Oslo-Software-Architecture/

Updated on April 16, 2022

Comments

  • Shiraz Bhaiji
    Shiraz Bhaiji about 2 years

    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. 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.

    We have though of the following possibilities:

    • Use 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
    • Use web services to read information from the asp.net web site and write the html on the PHP site.
    • Use WSRP (Web services Remote Portlets). Have tested this to display Sharepoint webparts on a Java site, have not tested with PHP.

    Has anyone tried any of these? Has a better suggestion? Is there any we should definatly avoid?

    Thanks

    Shiraz

  • Brian Lyttle
    Brian Lyttle almost 15 years
    How do you deal with situations where remotepage.aspx requires values to be posted to it, viewstate, or multiple postbacks?
  • Dan Diplo
    Dan Diplo almost 15 years
    You couldn't! I would only suggest this for pages that didn't postback and were relatively "flat". Even then, I don't think it's a great idea, but it might work in an MVC site or for simple "read-only" content.
  • JustJohn
    JustJohn almost 8 years
    We have PHP and .NET MVC/WebForms running on IIS in different website. No problem with speed. It used to be a problem but Microsoft has made huge leaps and bounds in getting PHP to work well with IIS. And why not? They want to conquer the world. Here is a great resource for this that MS has provided. php.iis.net