views:

573

answers:

3

In my asp.net-mvc application I need to include a page that shows a legacy page. The body of this page is created by calling an existing Perl script. This Perl script is externally hosted.

Is there a way to do something like this:

<!-- #Include virtual="http://www.example.com/theScript.plx"--&gt;
+1  A: 

Not as a direct include, because ASP.NET server-side-includes require the page to be compiled at the server.

You could use jQuery to download the HTML from that URL when the page loads, though I appreciate that's not perfect.

Alternatively (and I have no idea whether this will work) you could perform a WebRequest to the perl webpage from your ASP.NET MVC controller, and put the resulting HTML in the view as text. That way you could make use of things like output caching to limit the hits to the perl page if it doesn't change often.

Neil Barnwell
A: 

You could implement this in a low-key fashion by simply using a frame and setting the frame source to the url that needs to be included. This is quite simple and can be down without any server or client side scripting, so that'd be my preferred approach, if possible.

If you want the html to appear to come from your server, however, you'll need to manually include it - typically by using WebRequest as Neil says. You may wish to cache the remote page for performance, though, since it's a perl script, I'll assume the page is dynamic, so this might not be a great idea.

Eamon Nerbonne
A: 

If you wanted to do it all in one go, you could do an HTTP Request from the server and write the contents to the page?

Something like this:

Response.Write(GetHtmlPage("http://www.example.com/theScript.plx"));

Calling this method:

public String GetHtmlPage(string strURL)
{
    // the html retrieved from the page
    String strResult;
    WebResponse objResponse;
    WebRequest objRequest = System.Net.HttpWebRequest.Create(strURL);
    objResponse = objRequest.GetResponse();
    // the using keyword will automatically dispose the object 
    // once complete
    using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()))
    {
        strResult = sr.ReadToEnd();
        // Close and clean up the StreamReader
        sr.Close();
    }
    return strResult;
}

(Most code ripped blatantly from here and therefore not checked)

Damovisa
I took a similar approach at first. My controller would get the HTML and pass it through the TempData. The result that is returned from the plx however is an entire page (including head, body etc) with relative links. So it has to go in a frame anyway.
borisCallens
Ahh, I see what you mean, boris. A frame is probably the way to go then unless you want to go down the path of stripping out html you don't need - I wouldn't recommend that :)
Damovisa
Alternatively, you could clear the response first and then write out the page, but then you would be sending ONLY the response from the other server. If there's a standard layout, menu, or any other html you need to send, you'd lose it.
Damovisa