is it possible to understand at Code behind whether page is being called inside iframe or not
I need to understand that whether page is being called inside iframe or not at code behind. Is this possible?
I need to开发者_Go百科 determine it in master page code behind.
asp.net 4.0, C#
In general, no.
Of course you can emit client script that detects iframe and reloads the page with e.g. a querystring.
It's not possible. However there's a workaround this. You can use querystring and check on page load if that querystring contains value, for example:
<iframe src="Default.aspx?iframe=true" />
In your Default.aspx.cs
file:
protected void Page_Load(object sender, EventArgs e)
{
if(!string.IsNullOrEmpty(Request.QueryString["iframe"]))
{
if(Convert.ToBoolean(Request.QueryString["iframe"])
{
// this page is loaded in an iframe
}
}
}
精彩评论