0

I want to recognize if any page of my site called from an iframe in an external site

I can change my _layout.cshtml.

In other word I want to have two layout one for users visit my site directly an another layout for users that visit my site from another sites (other site use iframe for reference to my site)

My problem is how to detect this two type and change my layout?

Edit I need to know iframe in server side to can change it. I dont wan redirect user to certain action by javascrip I need a command like this in some of my view but how?

@{ 
if(ViewBag.Iframe == true)
{
 layout ="_Iframelayout.cshtml"
}
else
{
 layout ="_Normallayout.cshtml"
}

}
Behrouz Ghazi
  • 399
  • 2
  • 7
  • 23

2 Answers2

0

Check out this link. This link will help you identify if your site is opened within an iframe.

Once you identify this, you can redirect the user to a specific Controller Action and change your layout programmatically.

Community
  • 1
  • 1
TechnoBrat
  • 277
  • 1
  • 7
0

You can use following code thsis is the example..

<style>
  html { display :none; }
</style>
<script>
if(self==top){
  window.location = "http://www.mysite.com/my_layout.cs.html";
}else{
  window.location = "http://www.mysite.com/my_layout.cs.html";
}
</script>

You redirect your page to the specific type of layout base on self==top decision