Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect the entire page from MVC3 Razor iFrame page to a different URL

I have an razor page https://myDomain1.com/myFrame.cshtml with a "continue" button on it

this razor page is an iframe inside another parent.cshtml

When I click on the "Continue" button I want to redirect my entire page(including parent page) to https://myDomain2.com/default .

Given below is the ActionResult in my Controller

[HttpPost]
    public ActionResult myFrame(TestViewModel model)
    {

      Response.Redirect("https://myDomain2.com/default");

       return View(model);
    }

with my above code only the iframe part of the page is redirecting but my requirement is to redirect the entire page to https://myDomain2.com/default My problem here is that ,I want to redirect my entire page(including parent page) to https://myDomain2.com/default .

Please help me how to redirect the entire page to a different domain URL

like image 327
Lee Avatar asked Nov 23 '11 00:11

Lee


2 Answers

In the case that you must use this solution (sticking with frames), simply include the javascript content result - something along these lines:


    [HttpPost]
    public ActionResult myFrame(TestViewModel model)
    {
       return Content("<html><script>window.top.location.href = "http://www.whatever.com"; </script></html>");
    }

Your frames must be in the same domain though for this to work.

like image 122
Adam Tuliper Avatar answered Nov 10 '22 22:11

Adam Tuliper


HTTP does not allow you to specify the target frame in the response.

Instead, set target="_top" in the original <form>, or put a Javascript frame-buster in the target page.

like image 6
SLaks Avatar answered Nov 10 '22 21:11

SLaks