Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to tell if ASP.NET app is running inside a frame; using c#, not javascript

Posted on 2009-06-30
9
Medium Priority
?
915 Views
Last Modified: 2013-11-07
I need to be able to determine if my c# ASP.Net application is inside a HTML frame.  In Javascript, I would normally use:
if (top.location != location)

How can I do this in the code-behind of a user control?
0
Comment
Question by:alien_technology
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 3

Expert Comment

by:eirikurh
ID: 24749938
If your mainpage have a default.aspx as your mainpage, and your frame have another url like "main.aspx"
then you can check the url on the server side:
if (Request.Url.Segments.Length > 2)
{
  if (Request.Url.Segments[2].ToLower(CultureInfo.InvariantCulture) != "default.aspx")
  {
     //in Frame
  }
}
0
 

Author Comment

by:alien_technology
ID: 24750080
Thanks for the reply eirikurh, but I don't think that it does what I need.  

It appears that in your example, if main.aspx is loaded by itself, Request.Url.Segments[2] will be "main.aspx".  If main.aspx is loaded inside an iframe, Request.Url.Segments[2] will still be "main.aspx", won't it?  The page main.aspx still does not know that it was loaded inside a frame.
0
 
LVL 3

Expert Comment

by:eirikurh
ID: 24750430
See Request Referrer points to default.aspx when main.aspx is loaded in frame.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:alien_technology
ID: 24754937
But if a link in main.aspx does a postback or links to another page and then back, referrer would no longer point to default.aspx.  

Is there no .Net equivalent to Javascript's top.location?
0
 
LVL 3

Expert Comment

by:eirikurh
ID: 24757235
Do you have control over the frame page.

If i were you, i would add a parameter to the frame.

src="main.aspx?inframe=1
0
 

Author Comment

by:alien_technology
ID: 24757457
I could, but that would mean that the querystring would have to be updated for all links on all pages in the frame.  

Is there no way for a .Net page to access the parent frame to get the URL?  That would definitively indicate if it is in a frame.
0
 
LVL 3

Expert Comment

by:eirikurh
ID: 24759322
The server have no access to the Browsers DOM
Why do you need to check if the page is loaded in frame?
0
 

Author Comment

by:alien_technology
ID: 24798588
We are migrating applications that used to be stand-alone to now work in an iframe in DotNetNuke.  With a single code base, we want to display the header images and menuing if the app is on its own, but remove it if its in a DNN window since DNN can display that stuff.
0
 
LVL 3

Accepted Solution

by:
eirikurh earned 2000 total points
ID: 24809963
You could make a cookie on the client side
and read it later on server side

---Client side ---
var seconds = 60;
var date = new Date();
date.setTime(date.getTime() + (seconds*1000)); //1 minute expire
var expires = "; expires=" + date.toGMTString();
var framevalue = '0';
if (top.location != location)
{
  framevalue = '1';  
}
document.cookie = 'inframe'+"="+framevalue+expires+"; path=/";


--- Server Side ---
bool isFrame = false;
if (Response.Cookies["inframe"] != null)
{
  string cookieValue = Response.Cookies["inframe"].Value;
  if (cookieValue.Equals("1"))
    isFrame = true;
}
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question