Search code examples
javascriptasp.netnavigationmaster-pagesresponse.redirect

redirect the users to default page (no login) if user navigates to the page directly by typing the URL


I have an ASP.NET 3.5 intranet website which has a default page with a menu and when the user clicks on a menu item, I display the page for that menu item in an iframe embedded within the default page. but if the user types the URL of a page directly in the browser, then I would like to redirect him to the default page, because all the content pages do not have a menu. (Master Pages will solve this issue, but I can't use Master page here for a reason and don't want to go into those details). how to find out if user has arrived at the page directly by typing the URL or by clicking on the menu item, so that I can decide whether to redirect or not? Is this possible to find out? btw this is an intranet site and no login is required. thanks in advance.


Solution

  • You should use MasterPages for your problem, beacuse iFrames are not a good technique. But, you could try it with a litte JavaScript-Snippet in the content pages:

    <script type="text/javascript">
    if (top == self)
      window.location = "/index.html";
    </script>
    

    You simply check, if the loaded page is identical to your iFrame. If this is true, then your iFrame is loaded directly.