Prevent opening multiple windows in ASP. NET

Source: Internet
Author: User

This article from: http://code.msdn.microsoft.com/CSASPNETPreventMultipleWind-b1dd2bd6

 Csaspnetpreventmultiplewindows overview use: the project has strates 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 canGet 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  

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.