且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

ASP.net C#避免打开同一个窗口中两次

更新时间:2022-12-09 15:49:15

在这种情况下,你必须使用Cookie会话 - 中的System.Web在web.config中

In this instance you have to use cookieless sessions - in web.config in system.web

<sessionState mode="InProc" timeout="20" cookieless="UseUri" />

这是什么做的是插入会话ID到URL中,以便你喜欢的东西,www.host.com/(abc15284dndhjkdm)/app.aspx。 THISIS那么每个选项卡,因此用户可以唯一有每个标签uniqie会话。

what this does is insert a session id into the url so you get something like, www.host.com/(abc15284dndhjkdm)/app.aspx. thisis then unique per tab and so the user can have uniqie session per tab.

编辑: - 这里是code在web3.adprs.net/test/test1.aspx的aspx页面我会让我提以下

- here is the code for the aspx pages i show at web3.adprs.net/test/test1.aspx i mention below

Test1.aspx

Test1.aspx

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="test1.aspx.vb" Inherits="WebApplication4.test1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server">
    <title></title> </head>
     <body>
        <form id="form1" runat="server">
        <div>
        Enter User <asp:TextBox ID="user" runat="server"></asp:TextBox>
        <asp:Button ID="go" runat="server" Text="Go" />
        </div>
        </form>
    </body></html>

Test1.aspx.vb

Test1.aspx.vb

Public Class test1
    Inherits System.Web.UI.Page

    Private Sub go_Click(sender As Object, e As System.EventArgs) Handles go.Click
        Session("user") = user.Text
        Response.Redirect("test2.aspx")
    End Sub
End Class

Test2.aspx

Test2.aspx

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    Your user from session is <%=Session("user").ToString%>
    </div>
    </form>
</body>
</html>

的web.config

web.config

<?xml version="1.0"?>
<configuration>
  <system.web>
    <compilation debug="true" strict="false" explicit="true" targetFramework="4.0" />
    <sessionState mode="InProc" timeout="20" cookieless="UseUri" />
  </system.web>
  <system.webServer>
     <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
</configuration>

心连心