Xander Kage
Xander Kage

Reputation: 199

Add custom header to an iframe asp.net

There is a legacy .net application. In its content page , I need to open a MVC application. So I am using Iframe and opening the MVC application .

I am stuck as to how to send parameters to the MVC application via custom headers. I cant use query string as the paramter need to be sent is quite big.

Pls help.

<asp:Content ID="Content" ContentPlaceHolderID="MainContent" runat="server">
            <iframe id="frame" ></iframe>
    </asp:Content>

THis is the piece of code in my .net application. How to add headers when MVC appl is being invoked.

Upvotes: 0

Views: 1293

Answers (1)

John Wu
John Wu

Reputation: 52240

Don't know what you mean by passing data via "custom headers." Typically headers are for metadata, not data. If you have a significant amount of data to pass, the traditional way is via form/post. Here's one way to do it:

In the legacy app (the one that contains the iFrame):

<asp:Content ID="Content" ContentPlaceHolderID="MainContent" runat="server">
    <iframe id="frame" src="https://MyLegacyApp.com/Handoff.aspx"></iframe>
</asp:Content>

Note: Yes, the SRC of the iFrame points to the legacy app, not the new MVC app.

Add a new page to the legacy app called Handoff.aspx that looks like this:

<!-- Provide image while form is posting.  Style = centered. -->
<IMG SRC="Spinner.png" ALT="Please wait" style="position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);">

<!-- Hidden form that will post data to MVC site -->
<FORM Action="https://MyMVCApp.com/ReceiveHandoff" method="POST">
    <INPUT Name="Input1" Type="Hidden" Value="PLACE YOUR HUGE DATA HERE, OR IN SEVERAL HIDDEN TAGS IF YOU WANT.">
</FORM>

<!-- Script that autoposts the form -->
<SCRIPT>
    window.onload = function(){document.forms[0].submit();}
</SCRIPT>

Now the "ReceiveHandoff" page in your MVC site will be accessed via iFrame and initialized with the data passed in the form. To read the data, you can use one of these methods, for example:

var data = Request["Input1"];

Upvotes: 1

Related Questions