Detect if a page is within a iframe - serverside

后端 未结 5 1708
无人及你
无人及你 2021-01-03 22:22

How can I detect server-side (c#, asp.net mvc) if the loaded page is within a iframe? Thanks

5条回答
  •  北海茫月
    2021-01-03 23:01

    I don't think the server-side can do this, so why not put a hidden control in your page that will be in the iframe? When the URL in the iframe loads, you can add some client-side code to set the hidden input to indicate you are in an iframe. The easiest check would be on the client-side in an onload method, like this:

    // Set hidden input
    someHiddenInput.value = self != top
    

    It's more secure than the querystring, but it still might not be enough security for you.

    My 2 cents.

提交回复
热议问题