views:

338

answers:

2

hey again stackoverflowers

I'm migrating a website from old ASP (in VBScript) and there's certain stuuf I have to iFrame as to keep the old stuff working inside a new container.

on the aspx page I have an iFrame with the runat="server" attribute to make it available in the code behind file.

<iframe id="frmLoader" runat="server" scrolling="auto" width="100%" height="600px"></iframe>

now the issue, to get certain functionality I have to POST to a page (from the old site) to make it render differently and thus provide a response to the POST.

the following code resides in the Page_Load with of course parameters in the postData object

byte[] encData = new ASCIIEncoding().GetBytes(postData);

req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = encData.Length;

Stream dataStream = req.GetRequestStream();
dataStream.Write(encData, 0, encData.Length);
dataStream.Flush();
dataStream.Close();

WebResponse res = req.GetResponse();
StreamReader sr = new StreamReader(res.GetResponseStream());
string s = sr.ReadToEnd();
frmLoader.InnerHtml = s;

the pain here is that I can't seem to render the string into the iframe. with debugging I checked whether something should appear and it should, but it doesnt :p

anyone know how I get the string parsed into the iframe?

additionally, when triggering functionality in the iframe, the page should stay there, with the response to additional posts from the original site (old asp) I've been looking, but not finding answers.

+2  A: 

Have you tried this manually? Try the following:

<iframe>text</iframe>

How does that display in the browser?

It's because iframe doesn't work that way. Like an img tag, it needs a "src" attribute saying where the content comes from.

You may be able to create a .ashx file (HttpHandler), and have it do the POST and return the result. Your iframe would then be <iframe src="yourHandler.ashx"/>.

John Saunders
you would happen to have an easy how-to handy?
Jan W.
+1 classic iframe mistake - the contents of the iframe is another request entirely, you can't do anything whatsoever to it with *this* request other than decide what the iframe request is going to be
annakata
that's kinda confusing to me atm (last comment)
Jan W.
A: 

creating a handler would mean I have to create a custom handler for every old page I wish to use then?

I'm not that experienced in in-depth webdevelopment :)

in old ASP the previous developers put a lot of functionality into 1 page and by using the post message I can call upon these functions, rendering a different page each time.

can a handler, like you said, be built to accept a bunch of parameters to vary the post?

EDIT:

I just noticed another problem here. the handler does not have access to the session in which data resides to make the post I need it to. there's a different post per action ...

Jan W.
You've already got an issue with sharing session state between ASP and ASP.NET. Whatever technique you use to share it between the two, you could also use with the handler. In fact, you might try to not use session state at all here - factor out what a given page needs from session state and pass it in query string parameters, as an example.
John Saunders
Also, you probably could parameterize your handlers to the point where you have a much smaller number of handlers than pages. You'll probably find many of your pages do the same sort of thing in different ways. The common parameters could be factored out into parameters to the handler (which can accept query string parameters, etc).
John Saunders
I already solved the session problem using the httpcontext for this. there is however a new problem that arises, which I also posted herehttp://stackoverflow.com/questions/945004/iframed-asp-actions-trouble
Jan W.