8

I have a controller called ProductsController and I use the index method to load the index view with a web form inside called WebForm1.aspx, The index view has been set up and is working properly. Now I want to add an iframe in the index view to display the content of WebForm1.aspx. Both views are in the same folder Views/Products in the MVC project. I did the following:

    <iframe src="/ProductsController/Index?WebForm1.aspx" width="1000" height="400">

    </iframe>

my Views/web.config is set as next:

and the WebForm inheritance is as next:

<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

Yet the iframe display an error message: "HTTP 404 - The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable."

I tried also to add to my global.asax file the next line:

RouteTable.Routes.RouteExistingFiles = true;

but failed also,

The unique way I get iFrame displayed but empty is to use the full physical path as next:

    <iframe src="C\:Folder1\Folder2\ ...\Views\Products\WebForm1.aspx" width="1000" height="400">

    </iframe>

can someone explain why it does not work? And how to make it work? Thank you.

3 Answers 3

15

You should put your .aspx file (webform) out of the views folder, because normally any call from the browser is block by the "BlockViewHandler" (which you can see in the web.config file of the views folder).

In any other folder that you create, it should work without a controller. For example if you put it in "/webforms/webform1.aspx" that path is the one to use un the iframe.

UPDATE Here is an example with the new information in the question, hope it can help:

The controller:

public class ProductsController : Controller
{
    public ActionResult Index()
    {
        return View(); //Razor file in  Views/Products/Index.cshtml
    }

    public ActionResult ActionThatRetrieveAndAspx()
    {
        return View("WebForm1"); //Aspx file Views/Products/WebForm1.aspx
    }
}

The content of Products Index.html, calling the aspx file via an iframe:

@{
    ViewBag.Title = "Index title";
}

<h2>Index</h2>

Calling aspx file from iframe:

<iframe src="@Url.Action("ActionThatRetrieveAndAspx","Products")" width="1000" height="400"></iframe>

The content of Products WebForm1.aspx:

<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Title</title>
    </head>
    <body style="background-color: #999999; padding: 10px;">
        This is ActionThatRetrieveAndAspx WebForm1.aspx
    </body>
</html>
Sign up to request clarification or add additional context in comments.

3 Comments

"/webforms/webform1.aspx", do you mean that webforms is directly in the project root path ? if so it doesn't work.
This is the second answer... What I mean is that if you have an aspx file that inherits from System.Web.UI.Page (WebForm1.aspx), that kind of file should be placed outside of Views folder, that way you can call it by the "normal" url without passing the request through a controller... The other kind of aspx are the ones that inherits from "System.Web.Mvc.ViewPage" those files behave as Razor files, should be placed in views folder and the request is through a controller.
thanks for the explanations, updated my question, please take a look.
2

You can point to the actual location of the Webform.aspx file.

<iframe src="/FolderPath/WebForm1.aspx" width="1000" height="400">

    </iframe>

Your code asssumes that the MVC runtime would be looking at a folder called "ProductsController" and a sub folder called "Index"

If you Webform1.aspx file is really in that directory structure, change the src attribute to src="/ProductsController/Index/WebForm1.aspx"

Comments

0

I put the webform into the root folder of the MVC project and call it like this:

<iframe src="~/webform.aspx"...></iframe> 

I do not reference it in the controller.

A nice bonus to this technique is that you can easily navigate back to your MVC website by making navigation links in the webform open in target="_parent"

Comments

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.