Embed ASP page in ASP.NET

G

Guest

I am trying to figure out if it is possible to embed an ASP page in an
ASP.NET page. Our company uses a third-party system that creates reports in
classic ASP. I am creating a portal for our customers, using ASP.NET and
would like to seamlessly integrate the third-party's classic ASP page in the
portal.

I realize I can pass hidden form variables to the ASP page and open the ASP
page in a new instance of IE, but I'd like to find a more seamless way.

Thanks,
Roby2222
 
G

Guest

Thanks for the suggestion, but I'm really not a fan of frames. It seems that
users always get confused when they try to print, but they clicked on a
different frame (such as the menu frame) just before printing.

Does anyone know any other way?

Thanks,
Roby2222
 
S

Steven Cheng[MSFT]

Hi Roby,

As for this problem, I think we can consider different approachs according
to different scenairo:
1. If we want to display another page inside an existing page and the inner
page need to interact with the user, I think use a IFRAME element (or
frame) is suitable(seems also the only means).

2. As you mentioned that the ASP page use some report component, is it
displaying some graphic report and need to be print together with the
container page?
If so ,I think it's better to contain's the ASP page's output html as part
of the container ASP.NET page's output. In .net framework , the
HttpWebRequest class can help us to programly request a certain web
resource and retrieve back the response stream. Thus, we can use it to
manually request the ASP page in ASP.NET page's code behind and embeded the
ASP page's response html into the ASP.NET page's output ( for example , in
a <div> ..</div> ). And following is a simple sample on this:

============container aspx page==========
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>outer</title>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<table width="100%">
<tr>
<td>
<asp:Label id="lblTitle" runat="server">Below is the embeded ASP
Report</asp:Label>
</td>
</tr>
<tr>
<td>
<div id="divInner" runat="server"></div>
</td>
</tr>
</table>
</form>
</body>
</HTML>

============aspx page codebehind===============
public class outer : System.Web.UI.Page
{
protected System.Web.UI.HtmlControls.HtmlGenericControl divInner;
protected System.Web.UI.WebControls.Label lblTitle;

private void Page_Load(object sender, System.EventArgs e)
{
try
{
string url = Request.Url.ToString();
url = url.Substring(0,url.LastIndexOf("/")+1) + "inner.asp";
divInner.InnerHtml = GetPageOutput(url);
}
catch(Exception ex)
{
Response.Write("<br>" + ex.Message);
}
}

private string GetPageOutput(string url)
{
WebRequest wr = WebRequest.Create(url);
StreamReader sr = new StreamReader(wr.GetResponse().GetResponseStream());
return sr.ReadToEnd();
}

..................................

}

=============inner asp page =================
<table width="100%" align="center" border="1">
<%
for i = 1 to 5
%>

<tr>
<td>Report Item: <%= i %></td>
</tr>

<%
Next
%>
</table>


========================================

Hope helps. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
S

Sasa .

Hi,

I did not try this, but I guess that if you want to acomplish this the
way you described, you may try using HttpWebRequest/HttpWebResponse
class and then print out the result in your asp.net application.

Still, you should be aware that your server may suffer :)

Sasa .
 
S

Sasa .

I just checked the docs and it seems like that System.Net.WebClient is
doing the job (not HttpWebRequest as I said earlier) :)

Sasa .
 
G

Guest

Thanks for the help everyone. I think I'll give the HttpWebRequest idea a
try. The only thing I'm not sure about is that the ASP page will contain
links and is basically a site on it's own. If I use HttpWebRequest to stream
the first page into the DIV, then what would happen when a user clicks on a
link in the ASP page, which calls another ASP page? I'm guessing the target
ASP page would replace the ASP.NET page with the embeded ASP page, rather
than keep the ASP.NET "container" and just replace the DIV section with the
new page.

Thanks,
Rob
 
G

Gerry Hickman

Roby2222 said:
ASP page would replace the ASP.NET page with the embeded ASP page, rather
than keep the ASP.NET "container" and just replace the DIV section with the
new page.

That's why frames are so cool. You can always give them a "print" button
if they're that green.
 
S

Steven Cheng[MSFT]

Hi Gerry,

yes, since the HttpWebRequest approach embeded the asp page's response HTML
into the asp.net page, so all the hyperlinks will also be treated as the
link in the asp.net page. And in addition to replace the currently page
when we hit the link, since we generally use relative path in hyperlink it
is likely that the links be broken. As for this point, Iframe seems more
reasonable. Anyway, what approach to use depends on your acutal scenairo.

Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top