单个用户查看时代码有效,但当多个用户查看同一页面时,页面会变得疯狂

时间:2015-01-28 19:05:37

标签: asp.net vb.net

以下是问题页面的aspx和vb代码文件。只有一个用户登录并查看时,问题页面才有效。虽然,当另一个用户登录并查看同一页面时,这发生了ard(i)<> XXZ(ⅰ)

Then Response.Redirect("../vwall/vwall_tour.aspx?tour_id=" & ddlAvailableTours.SelectedValue)
                End If

页面重复重新加载。所以,ard(i)<> xxz(i)在多个用户登录查看时发生。一个用户如何受到另一个用户在同一页面上查看和选择的影响?一个用户一切都很好,而不是当多个用户在这个页面上玩游戏时。

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="vwall_tour.aspx.vb" Inherits="vwall_tour2" %>

<!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">

<script src="../js/jquery-1.6.1.min.js" type="text/javascript"></script>
<script src="../flowplayer/flowplayer-3.2.4.min.js" type="text/javascript">         </script> 
 <script type="text/javascript" src="../flowplayer/flowplayer-3.2.4.min.js">            </script>

<script type="text/javascript">
function OpenTourManager() {
    document.location.href = 'manage_tours.aspx';
    //document.location.href = 'manage_tours.aspx?tourid=' +   
      document.getElementById('ddlAvailableTours').options[document.getElementById('dd    lAvailableTours').selectedIndex].value;
}
</script>
</head>
<body>

<form id="form1"   style="height:100%; vertical-align:middle" runat="server">
<table border=0 cellpadding=0 cellspacing=0 width=100% background="../images/gray.jpg">
<tr>
<td><img src="../images/cyberco-banner.gif" height="35px" alt="CYBERCO" /></td>
<td><asp:Button runat="server" ID="btnSignOut" Text = "Sign Out" /></td>               
<td><input type = "button" value ="Change Password" onclick="javascript: document.location.href = '../changepassword.aspx';" id="btnChangePass"/></td>
<td></td>
<td><asp:Label ID ="lblUsername" runat="server"> </asp:Label></td>
<td width="400px">&nbsp;</td>
<td><asp:DropDownList ID = "ddlAvailableTours" runat="server" Width="250px" OnSelectedIndexChanged="SelectionChanged" AutoPostBack="True"></asp:DropDownList></td>
<td><asp:Button runat="server"   id="btnSetDefaultTour"  Text="Set as default" /></td>
<td><input type='button' value='Manage Video Wall' onclick="javascript: OpenTourManager(); "/></td>
<td><input type="hidden"  id ="startstop" onclick= "javascript: vwallStartStop();"  /></td><td>(Fullscreen->&nbsp;F11)<!--<input type="button" value="Fullscreen mode" onclick="    toggleFull()" />--></td>
 </tr>
   </table>
  <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true"  /><asp:Timer ID="Timer1" OnTick="Timer1_Tick" runat="server" Interval="5000" /><table border=0 cellspacing=0 cellpadding=0 id="main" style="height:100%; width:100%; padding:0px; margin:0px; background-color:#000000;">
<tr><td align=right style="vertical-align:top; border:0px; padding:0px;" align=top padding=0 valign=top class='header_row' id="tdheader">
    <div id="header" class="style1">


            <div id = "clockid"  style="visibility:hidden;  border:0px; padding:0px;" > clock</div>&nbsp;
       <!---<table border=2 cellpadding=0 cellspacing=0 padding=0 style="text-align:center;height:564;width:100%;padding:0;margin:0;" bgcolor=#425081 >-->
                    <tr>
                        <td padding=0  width=0px" width=0%>
                            <asp:UpdatePanel ID="up_setdefault" UpdateMode="Conditional" runat="server" RenderMode="Inline">    

                                <Triggers><asp:AsyncPostBackTrigger ControlID="Timer1" /></Triggers>
                                <ContentTemplate>
                                    <asp:Label id="StockPrice" runat="server"></asp:Label>
                                    <fieldset style="border:0; margin=0px; cellpadding=0; padding=0px; cellspacing=0; align=right; width=0px;" width=0%>    
                                    </fieldset> 
                                </ContentTemplate>
                            </asp:UpdatePanel> 
                        </td>
                    </tr>
                <!--</table>-->
                <tr><td padding=0 style="border:0px; padding:0px;">    <asp:Literal runat="server" ID="litTableInner1"></asp:Literal></td></tr></table>
<!-- cut script -->

<asp:Literal runat="server" ID="litCreatePlayersScript"></asp:Literal>
<asp:Literal runat="server" ID="litCreateUpdateScript"></asp:Literal>                        
</form>
</body>
</html>

然后是vb代码文件......

Imports System.Data.SqlClient
Imports System.Data
Imports System.Net

Public Class vwall_tour2
Inherits System.Web.UI.Page
Public Shared xxz(9) As String
'Protected default_wstr As String = ConfigurationManager.AppSettings("default_wstr")
'Dim xxz = {"Off", "Off", "Off", "Off", "Off", "Off", "Off", "Off", "Off"}

Protected Sub vwall_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    Dim thisUser As New cyberUser(User.Identity.Name, (ConfigurationManager.ConnectionStrings("timsConnectionString").ToString()))
    Me.lblUsername.Text = User.Identity.Name

    Dim auto_refresh_users As String()
    auto_refresh_users = Split(ConfigurationManager.AppSettings("wall_logins_noexpire").ToString, ",")
    Dim lausername As String
    For Each lausername In auto_refresh_users
        If Trim(lausername) = User.Identity.Name Then
            Dim s As New StringBuilder
            s.AppendLine("setTimeout ( 'reloadit();', reloadtime ); ")
            ScriptManager.RegisterStartupScript(Me, Me.GetType(), "loadAfterSigninFromVwall", s.ToString(), True)
            Exit For
        End If
    Next
    ' if not found, will time out after 2 hrs and have to log in again 

    Dim selected_tour_id As Integer
    If Not Page.IsPostBack Then
        'btnAdmin.Visible = False

        Dim ds As DataSet
        ds = dataFetcher.fillDataset("User_SelectTours " & thisUser.userid, ConfigurationManager.ConnectionStrings("timsConnectionString").ConnectionString, False)
        ddlAvailableTours.DataSource = ds
        ddlAvailableTours.DataValueField = "tour_id"
        ddlAvailableTours.DataTextField = "tour_name"
        ddlAvailableTours.DataBind()

        If Not Request.QueryString("tour_id") Is Nothing Then
            Try
                selected_tour_id = Convert.ToInt16(Request.QueryString("tour_id"))
            Catch ex As Exception
                selected_tour_id = ddlAvailableTours.Items(0).Value
            End Try
        ElseIf thisUser.default_tour_id <> -1 Then
            selected_tour_id = thisUser.default_tour_id
        Else
            selected_tour_id = ddlAvailableTours.Items(0).Value
        End If

        Dim itemfound As Boolean = False
        Dim item As ListItem
        For Each item In ddlAvailableTours.Items
            If item.Value = selected_tour_id Then

                item.Selected = True
                itemfound = True
                Exit For
            End If
        Next

        If Not itemfound Then 'default or querystring tour_id not found 
            ddlAvailableTours.SelectedIndex = -1
            ddlAvailableTours.Items(0).Selected = True
        End If
        Me.ddlAvailableTours_SelectedIndexChanged(Nothing, Nothing)
    End If ' notpostback 

End Sub

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
    StockPrice.Text = DateTime.Now.ToLongTimeString()
    'TimeOfPrice.Text = DateTime.Now.ToLongTimeString()
End Sub

Sub Timer1_Tick(ByVal sender As Object, ByVal e As EventArgs)
    If User.Identity.IsAuthenticated Then
        Dim thisUser As New cyberUser(User.Identity.Name, (ConfigurationManager.ConnectionStrings("timsConnectionString").ToString()))
        ''load the page 

        Dim selected_tour_id As Integer
        selected_tour_id = ddlAvailableTours.SelectedValue

        Dim t As user_Tour
        For Each t In thisUser.user_Tours
            If t.tour_id = selected_tour_id Then
                StockPrice.Text = GetOverrideStatus(t)
                Exit For
            End If
        Next

        ''''''
    End If
End Sub

Function GetOverrideStatus(ByVal tour As user_Tour) As String
    On Error Resume Next

    Dim rstrf As New StringBuilder
    'create the playlist string 

    Dim playlists As String()
    Dim phaseitems As String()
    Dim numPlayers As Integer = tour.num_cols * tour.num_rows
    ReDim playlists(numPlayers - 1)
    Dim dsd As DataSet
    Dim stream_address As String
    Dim VideoLabel As Object
    Dim ard(9) As String

    'ard = {"Off", "Off", "Off", "Off"}
    Array.Clear(ard, 0, ard.Length)
    For Each p In tour.phases
        phaseitems = p.str_all_items.Split(",")

        For i = 0 To numPlayers - 1

            Dim s_id As String = phaseitems(i)
            If p.tour_phase_id > 1 Then
                playlists(i) &= ", "
            End If
            If Not s_id = "empty" And Not s_id = "" Then
                dsd = dataFetcher.fillDataset("ListImageAllFields '" & s_id & "'", ConfigurationManager.ConnectionStrings("timsConnectionString").ConnectionString, False)

                ard(i) = dsd.Tables(0).Rows(0).Item("active_override")
                ' rstrf.AppendLine("A" + ard(i))
                ' rstr.AppendLine(ard(i))
                If ard(i) <> xxz(i) Then
                    'Response.Write("<script>window.opener.location.href = window.opener.location.href </script>")
                    Response.Redirect("/media_dev/vwall/vwall_tour.aspx?tour_id=" & ddlAvailableTours.SelectedValue)
                End If

                ' If ds.Tables(0).Rows(0).Item("active_override") = "On" Then
                'Response.Redirect("../default.aspx")
                ' End If


                'playlists(i) &= "'" & stream_address & "'"
            Else ' empty spot 
                'playlists(i) &= "'../images/tours/tour_empty_space.png'"

            End If 's not blank 
        Next
    Next
    'If ard(0) <> xxz(0) Or ard(1) <> xxz(1) Or ard(2) <> xxz(2) Or ard(3) <> xxz(3) Then
    'Response.Write("<script>window.opener.location.href = window.opener.location.href </script>")
    'Response.Redirect("../vwall/vwall_tour.aspx?tour_id=" & ddlAvailableTours.SelectedValue)
    ' End If

    'Return ard.ToString("C")
    Return ard(0).ToString() + ard(1).ToString() + ard(2).ToString() + ard(3).ToString() + ard(4).ToString() + ard(5).ToString() + ard(6).ToString() + ard(7).ToString() + ard(8).ToString()
End Function

Sub writeTableString(ByVal tour As user_Tour)
    Dim returnstr As New StringBuilder
    Dim td_width, td_height As Integer

    td_width = Math.Floor(100 / tour.num_cols)
    td_height = Math.Floor(100 / tour.num_rows) 'was 90

    Dim rstr As New StringBuilder
    Dim countinner, countouter As Integer
    countinner = 0
    countouter = 0
    Do
        rstr.AppendLine("<tr>")
        Do
            rstr.AppendLine("<td style='width:" & td_width & "%; height:" & td_height & "%;'><a runat='server' id='player" & (countinner + (countouter * tour.num_cols)) & "' href='#'></a></td>")
            countinner += 1
        Loop Until countinner = tour.num_cols
        rstr.AppendLine("</tr>")
        countouter += 1
        countinner = 0
    Loop Until countouter = tour.num_rows
    rstr.AppendLine("<script> document.getElementById('tdheader').colSpan='" & tour.num_cols & "';</script>")

    Me.litTableInner1.Text = rstr.ToString
End Sub

Sub writeScriptForPlayers(ByVal tour As user_Tour)
    On Error Resume Next
    Dim rstr As New StringBuilder
    'create the playlist string 
    Dim playlists As String()
    Dim phaseitems As String()
    Dim numPlayers As Integer = tour.num_cols * tour.num_rows
    ReDim playlists(numPlayers - 1)
    Dim ds As DataSet
    Dim stream_address As String
    Dim VideoLabel As Object
    Array.Clear(xxz, 0, xxz.Length)
    For Each p In tour.phases
        phaseitems = p.str_all_items.Split(",")

        For i = 0 To numPlayers - 1

            Dim s_id As String = phaseitems(i)
            If p.tour_phase_id > 1 Then
                playlists(i) &= ", "
            End If
            If Not s_id = "empty" And Not s_id = "" Then
                ds = dataFetcher.fillDataset("ListImageAllFields '" & s_id & "'", ConfigurationManager.ConnectionStrings("timsConnectionString").ConnectionString, False)

                xxz(i) = ds.Tables(0).Rows(0).Item("active_override")
                rstr.AppendLine("B" + xxz(i))
                If ds.Tables(0).Rows(0).Item("active_override") = "Off" Then
                    If ds.Tables(0).Rows(0).Item("hq_viewcapable") = "Y" Then
                        If ds.Tables(0).Rows(0).Item("hq_firstresponder") = "Y" Then
                            stream_address = ds.Tables(0).Rows(0).Item("AddressRTMP_hq").ToString()
                        Else
                            stream_address = ds.Tables(0).Rows(0).Item("AddressRTMP").ToString()
                        End If
                    Else
                        stream_address = ds.Tables(0).Rows(0).Item("AddressRTMP").ToString()
                    End If
                Else : stream_address = "../overridden.swf"
                End If
                playlists(i) &= "'" & stream_address & "'"
                '  Else ' empty spot 
                'playlists(i) &= "'../images/tours/tour_empty_space.png'"

            End If 's not blank 

        Next
    Next

    ' end creating playlist strings 

    Dim countinner, countouter As Integer
    countinner = 0
    countouter = 0
    rstr.AppendLine("<script type='text/javascript'>")
    Do
        Do
            countinner += 1
        Loop Until countinner = tour.num_cols
        countouter += 1
        countinner = 0
    Loop Until countouter = tour.num_rows
    ''write the players 
    countinner = 0
    countouter = 0
    Do
        Do
            rstr.AppendLine("flowplayer('player" & (countinner + (countouter * tour.num_cols)) & "', '../flowplayer/flowplayer.commercial-3.2.5.swf', {  key: '#$34tg5y5y5hytr', logo: { url:'../images/CYBERLOGO.PNG', opacity: 0.65, top: 10, right: 10, fullscreenOnly: false }, playlist: [" & playlists(countinner + (countouter * tour.num_cols)) & "], clip: { provider: 'CYBERCO', live: true, onBegin: function () { clearTimer(); }, onBeforeFinish: function () { this.getPlugin('play').hide(); return false;   } }, onLoad: function () { setTimer(); }, onPlaylistReplace: function () { setTimer(); }, onError: function () { error(); }, play:{ opacity:0.0, label:null, replayLabel: null }, onFinish: function(){ this.play(); }, plugins: { CYBERCO: { url: '../flowplayer/flowplayer.rtmp-3.2.3.swf', live: true, controls: { autoHide: true}}} })")
            'logo: { url:'/first_resp/images/cyberco-banner.gif', opacity: 0.4, bottom: 20, right: 20 }, 
            ' rstr.AppendLine("flowplayer('player" & (countinner + (countouter * tour.num_cols)) & "', '../flowplayer/flowplayer.commercial-3.2.5.swf', {  key: '#$34tg5y5y5hytr', logo: { url:'..images/CYBERLOGO.PNG', opacity: 0.65, top: 10, right: 10, fullscreenOnly: false }, playlist: [" & playlists(countinner + (countouter * tour.num_cols)) & "], clip: { provider: 'CYBERCO', live: true, onBegin: function () { clearTimer(); }, onBeforeFinish: function () { this.getPlugin('play').hide(); } }, onLoad: function () { setTimer(); }, onPlaylistReplace: function () { setTimer(); }, onError: function () { error(); }, plugins: { CYBERCO: { url: '../flowplayer/flowplayer.rtmp-3.2.3.swf', live: true, controls: { autoHide: true}}} })")
            countinner += 1
        Loop Until countinner = tour.num_cols

        countouter += 1
        countinner = 0
    Loop Until countouter = tour.num_rows
    rstr.AppendLine("</script>")
    Me.litCreatePlayersScript.Text = rstr.ToString
End Sub

Public Function loadWallData(ByVal wstr As String) As DataSet
    Try
        'If Me.loggedin Then 
        Dim conn As New SqlConnection(ConfigurationManager.ConnectionStrings("timsConnectionString").ConnectionString)
        Dim dsStreams As New DataSet
        'add the quotes to the strings 
        wstr = wstr.Replace(",", "','")
        wstr = "'" & wstr & "'"

        Dim sqltext As String = "[User_SelectVWallStreams]  " & wstr
        Dim da As New SqlDataAdapter
        Dim Command As New SqlCommand
        Command = New SqlCommand(sqltext, conn)
        'Command.CommandType = CommandType.StoredProcedure
        da.SelectCommand = Command
        da.Fill(dsStreams)
        Return dsStreams
    Catch ex As Exception
        Throw New Exception(ex.Message)
    End Try
End Function

Protected Sub SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs)
    Response.Redirect("../vwall/vwall_tour.aspx?tour_id=" & ddlAvailableTours.SelectedValue)
End Sub

Protected Sub ddlAvailableTours_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlAvailableTours.SelectedIndexChanged
    If User.Identity.IsAuthenticated Then

        Dim thisUser As New cyberUser(User.Identity.Name, (ConfigurationManager.ConnectionStrings("timsConnectionString").ToString()))

        ''load the page 

        Dim selected_tour_id As Integer
        selected_tour_id = ddlAvailableTours.SelectedValue

        If selected_tour_id = thisUser.default_tour_id Then
            Me.btnSetDefaultTour.Enabled = False
        Else

            Me.btnSetDefaultTour.Enabled = True
        End If
        Dim t As user_Tour
        For Each t In thisUser.user_Tours
            If t.tour_id = selected_tour_id Then
                'selected_tour_id = ddlAvailableTours.SelectedValue
                writeTableString(t)
                writeScriptForPlayers(t)
                ' Response.Redirect("../vwall/vwall_tour.aspx?tour_id=" & selected_tour_id)
                Exit For
            End If
        Next
    End If

End Sub

Protected Sub btnSetDefaultTour_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSetDefaultTour.Click
    If User.Identity.IsAuthenticated Then
        Dim thisUser As New cyberUser(User.Identity.Name, (ConfigurationManager.ConnectionStrings("timsConnectionString").ToString()))
        thisUser.UpdateDefaultTour(Me.ddlAvailableTours.SelectedValue)
        Me.btnSetDefaultTour.Enabled = False
    End If

End Sub

Protected Sub btnSignOut_Click(sender As Object, e As System.EventArgs) Handles btnSignOut.Click
    FormsAuthentication.SignOut()
    'delete the cookie (or will be infinite loop) 
    'delete the cookie 
    Dim aCookie As HttpCookie
    If Request.Cookies("cyber_Load") Is Nothing Then
        'Response.Cookies.Add(aCookie)
        Response.Redirect("../default.aspx")
    Else
        aCookie = Request.Cookies("cyber_Load")
        aCookie.Expires = DateTime.Now.AddDays(-1D)
        Response.Cookies.Add(aCookie)
        Response.Redirect("../default.aspx")
    End If
End Sub

End Class

1 个答案:

答案 0 :(得分:0)

原因是:

Public Shared xxz(9) As String

通过将变量声明为Shared,只存在一个变量实例,由所有用户共享。任何用户放入变量的内容对所有其他用户都是可见的。

您希望将数组存储在Session集合中,以便每个用户可以拥有自己的一个数组。

将数组变量声明为实例变量,这样它就是当前页面的本地变量,并且还没有创建实际的数组:

Public xxz As String()

在代码的开头,从Session集合中获取数组,或者如果之前没有数组则创建一个新数组:

xxz = DirectCast(Session("xxz"), String())
If xxz Is Nothing Then
  ReDim xxz(9)
  Session("xxz") = xxz
End If