how to do Employing defensive code in the UI to ensure that the current frame is the most top level window in csharp

Code Example - how to do Employing defensive code in the UI to ensure that the current frame is the most top level window in csharp

                
                        <script>
    try {
        if (top.location.hostname != self.location.hostname) throw 1;
    } catch (e) {
        top.location.href = self.location.href;
    }
</script>