C# – Detect if the page is in a frame from code behind

asp.netciframe

Is there a way to detect if my page is inside of a frame from my C# ASP.NET Code Behind?

I know there are ways to break out of frames, or detect frames, using javascript, but I'm not interested in that for this case. I want to know if there is a way to detect the frame server-side before the page makes it's first trip to the browser, i.e. if there is some kind of indication of this in the request.

Best Answer

Nope, there's nothing sent in the headers of the request indicating that the page is in a frame - and that's all you really have to go on.

The best you could do is take a look at the Referrer property, and if it comes from a known framing site (i.e. images.google.com etc) treat it as suspicious.