ASP page inside ASPX page = possible?

Is there a way to insert an .asp page into a .aspx page? I am trying to integrate a table from the asp page into the current aspx conversion of a mobile site. I am new to ASP and .NET; therefore, I am seeking ways to start.

Thank you in advance for your help.

how about having that in an iframe.

Hmm, that is interesting. I could see that maybe working; however, iframes don’t meet code standards anymore, so I want to ensure I am keeping current. However, thank you for this idea.

Wasn’t it included in HTML5?

iframes are definitlely still a standard. If anything asp.old is not a standard anymore. So other that a complete rewrite or iframe, I do not think you have another option. I am not sure if and <!–#include–> would work or not, but it might be worth a shot

Here is one way to go about it, this works by by scraping the content of the ASP page. I’m assuming you are using VB as you are coming from a Classic ASP background.


Imports System.Web
Imports System.Net
Imports System.IO

		''' <summary>
		''' Scrapes the HTML of the given URL
		''' </summary>
		''' <param name="Url">The URL to Scrape</param>
		''' <returns>A string containg the HTML</returns>
		Public Shared Function ScreenScrape(ByVal Url As String) As String
			Dim returnString As String = String.Empty

			Dim response As WebResponse
			Dim request As WebRequest

			If Url.StartsWith("http://") Then
				' full URL passed
				request = HttpWebRequest.Create(Url)
			Else
				' Partial Path passed, build the URL
				Dim Domain As String = HttpContext.Current.Request.ServerVariables("SERVER_NAME")
				If Not Url.StartsWith("/") Then Url = "/" + Url
				request = HttpWebRequest.Create("http://" + Domain + Url)
			End If

			Try
				response = request.GetResponse()
				Using sr As New StreamReader(response.GetResponseStream())
					returnString = sr.ReadToEnd()
				End Using

			Catch ex As Exception
               ' if an error is returned, view the HTML source code to see what the exception message is.
				returnString = String.Format("{0}<p>There was an error retrieving the HTML</p>{0}<!-- {1} -->", Environment.NewLine, ex.Message)
			End Try

			Return returnString
		End Function

Just place a Literal control on the page where you would like to have the injected code and call the function like this:

Literal1.Text = ScreenScrape("/myPage.asp")

Edit: Consider caching the output string.