开发者

is it possible to understand at Code behind whether page is being called inside iframe or not

开发者 https://www.devze.com 2023-04-10 15:06 出处:网络
I need to understand that whether page is being called inside iframe or not at code behind. Is this possible?

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
        }
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号