zoukankan      html  css  js  c++  java
  • [转]Prevent opening multiple windows in ASP.NET

    本文转自:http://code.msdn.microsoft.com/CSASPNETPreventMultipleWind-b1dd2bd6

    CSASPNETPreventMultipleWindows Overview
     
    
    Use:
     
    
    The project illustrates how to detect and prevent multiple windows or 
    tab usage in Web Applications.
     
    Demo the Sample. 
    
    Please follow these demonstration steps below.
     
    Step 1: Open the CSASPNETPreventMultipleWindows.sln.
     
    Step 2: Expand the CSASPNETPreventMultipleWindows web application and press 
           Ctrl + F5 to show the Default.aspx.
     
    Step 3: We will see two links on the page. First, you can Left click one
            of them jump to correct link(Like Nextlink.aspx and Nextlink2.aspx).
     
    Step 4: Then, you can right click these links and choose Open In New Tab 
           or Open In New Window,and you will find the link not available.
     
    Step 5: you can even copy the right url and Paste it in the browser address bar for
            test.but you can not achieve your goal.
     
    Step 6: Validation finished.
     
    
    Code Logical:
     
    
    Step 1. Create a C# "ASP.NET Empty Web Application" in Visual Studio 2010 or
            Visual Web Developer 2010. Name it as "CSASPNETPreventMultipleWindows".
     
    Step 2. Add one folder, "UserControls".Add two User Controls in this folder,
            "DefaultPage.ascx","NextPage.ascx".
     
    Step 3. Add five web forms in the root directory,"Default.aspx","InvalidPage.aspx"
            ,"Main.aspx","NextLink.aspx","NextLink2.aspx".
     
    Step 4. Move DefaultPage.ascx user control on Default.aspx file and move
            NextPage.ascx user control on all other files extension name are ".aspx".
             In Defalut.aspx.cs page, we have a method generate unique random number:
             [code]
            public string GetWindowName()
            {
                string WindowName = Guid.NewGuid().ToString().Replace("-", "");
                Session["WindowName"] = WindowName;
                return WindowName;
            }
             [/code]
             And window.name will recieve this unique string,we use window.name to prevent
             mutiple windows and tabs. 
            [code]
             //set window.name property
            window.open("Main.aspx", "<%=GetWindowName() %>");
     
             //If this window name not equal to sessions,will be goto InvalidPage
           if (window.name != "<%=GetWindowName()%>") {
              window.name = "InvalidPage";
              window.open("InvalidPage.aspx","_self");      
           }
            [/code]
     
    Step 5. Write the codes like the sample.you can get more details from comments in
            the sample file.
             
    Step 6. Build the application and you can debug it.
     
    
    
    References:
     
    
    MSDN: User control
     http://msdn.microsoft.com/en-us/library/fb3w5b53.aspx
     
  • 相关阅读:
    数独小算法,测试通过(Java)
    OC运行时和方法机制笔记
    AlertView点击确定后再执行后面的代码
    对第三方库集成方式的分析
    当程序进入后台时执行长时间代码
    iOS开发之GCD使用总结
    缓存网络请求的结果
    防止 NSTimer retain 作为 target 的 self
    获取设备唯一码
    原生网络请求以及AFN网络请求/异步下载
  • 原文地址:https://www.cnblogs.com/freeliver54/p/3091300.html
Copyright © 2011-2022 走看看