[转]Prevent opening multiple windows in ASP.NET
2013-05-21 19:00
381 查看
本文转自:http://code.msdn.microsoft.com/CSASPNETPreventMultipleWind-b1dd2bd6
And window.name will recieve this unique string,we use window.name to prevent
mutiple windows and tabs.
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 [/code]
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; }
And window.name will recieve this unique string,we use window.name to prevent
mutiple windows and tabs.
//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"); }
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 [/code]
相关文章推荐
- how to prevent multiple login for same user in asp.net
- Prevent Multiple Logins Using the Cache in ASP.NET
- How to prevent multiple clicks of a submit button in ASP.NET
- 【引】How to Choose the Best Way to Pass Multiple Models in ASP.NET MVC
- ASP.NET Dropdownlist 错误 "Cannot have multiple items selected in a DropDownList."
- Four Ways Of Handling Multiple Submit Buttons In ASP.NET MVC
- 【转载】在ASP.NET 2.0 中如何使用多个Sitemap文件【Using Multiple Sitemap Files in ASP.NET 2.0--英文】
- ASP.NET Dropdownlist 错误 "Cannot have multiple items selected in a DropDownList."
- Session state cannot be used in ASP.NET with Windows SharePoint Services
- Running multiple versions of the Framework in ASP.NET
- Working with Windows Workflow Foundation in ASP.NET
- Working with Windows Workflow Foundation in ASP.NET
- How to Choose the Best Way to Pass Multiple Models in ASP.NET MVC
- Working with Windows Workflow Foundation in ASP.NET
- How to integrate custom security policy with Windows domain authentication in ASP.NET
- Single sign-on across multiple applications in ASP.NET(Asp.Net跨应用单点登录[转自CodeProject])
- Build User rights control system in Asp.net.(Windows Form Authentication)
- Using the ReportViewer ASP.NET Control in Windows Azure
- Mixing Forms and Windows Security in ASP.NET
- Upload Large File In asp.net or website in Windows Azure .