0

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.

1
  • What do you mean exactly by 'quite big'? Commented Oct 6, 2016 at 15:00

1 Answer 1

1

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"];
Sign up to request clarification or add additional context in comments.

2 Comments

I wanted to ask 1 more thing ..how to invoke a javascript function sitting in parent application from child iframe .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.