p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

proasp_codeclinic thread: Session Dictionary


Message #1 by tnogueira@m... on Tue, 3 Apr 2001 15:54:36
It isn't these lines to which I referred.  Somewhere after the calculations
and manipulations to the local dictionary I should see:

Set Session("dictionary") = oDictionary
Set oDictionary = Nothing

In addition, I see direct value replacement happening to the dictionary in
session.  What I am saying is manipulate the values in the local dictionary
and then write the local dictionary as a replacement to the session
dictionary in total.

This way you are setting the session dictionary to the current dictionary
and you should avoid any duplicate values.

Michael

----- Original Message -----
From: "Alex Shiell, ITS, EC, SE" <alex.shiell@s...>
To: "Code Clinic" <proasp_codeclinic@p...>
Sent: Wednesday, April 04, 2001 5:06 AM
Subject: RE: Session Dictionary


Sorry, I assumed that went without saying

I should have added the lines

Dim oDictionary
set oDictionary = Session("dictionary")

to my example

-----Original Message-----
From: Michael A. Michalski [mailto:mmcihalski@n...]
Sent: Tuesday, April 03, 2001 7:28 PM
To: Code Clinic
Subject: Re: Session Dictionary


If I am reading the code correctly, there is a bigger issue.  The dictionary
object being stored in Session is going to cause a huge performance drain as
well as scalability problem.  The dictionary object is not threaded properly
for use in Session scope.

If you must use it, create a local dictionary object on the page and set it
to the session dictionary object.  Perform any manipulations to the local
dictionary, set the session dictionary to the local dictionary, and destroy
the local dictionary.  Do not make changes directly to the dictionary in
session.

Michael

----- Original Message -----
From: "Alex Shiell, ITS, EC, SE" <alex.shiell@s...>
To: "Code Clinic" <proasp_codeclinic@p...>
Sent: Tuesday, April 03, 2001 11:49 AM
Subject: RE: Session Dictionary


You must have a bit of code which adds keys in your ASP page - use the
exists property to test if a key already exists before adding it.

something like this:

if not oDictionary.Exists(sKey) then oDictionary.Add(sKey, sValue)

-----Original Message-----
From: tnogueira@m... [mailto:tnogueira@m...]
Sent: Wednesday, April 04, 2001 4:11 AM
To: Code Clinic
Subject: Session Dictionary


     Hi All,

     I´m having a problem with a dictionary in a session scope, the number
of items in the dictionary grows every time the page is reload. I realy
don´t know the cause.


    Thanks for any help.

    Tiago

    p.s: sorry for the bad english

Here is the code i´m using



<%Option Explicit%>
<html>

<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-
8859-1">
<link rel="stylesheet" href="estilo.css">
<script language="JavaScript" src="ic_imgfunc.js"></script>
<script language="JavaScript" src="menu.js"></script>
</head>

<body bgcolor="<%=azul5%>" background="../imagens/fundo_abertura.jpg"
onLoad="MM_preloadImages
('../imagens/admin2.gif','../imagens/op2.gif','../imagens/relat2.gif','../i
magens/cad2.gif','../imagens/reports2.gif','../imagens/monitor2.gif','../im
agens/analyser2.gif','../imagens/faleconosco2.gif','../imagens/help2.gif','
../imagens/sobre2.gif','../imagens/fechar_hover2.gif')">

<!--#include file="ic_conexao_open.asp"-->
<!--#include file="ic_cores.asp"-->

<%
Dim obj
Dim rs
Dim objDict

Set obj = Server.CreateObject("intradesk2001.clslogin")
Dim ObjDictStored
ObjDictStored = Session("ObjDictStored")

Dim obj_menu
Dim Desc
Dim link
Dim dep
Dim bMenu2
Dim bMenu3
Dim esp
Dim ini
Dim adm
Dim rel
Dim cad
Dim ope
Dim i
Dim count

obj_menu = 0
dep = 0
adm = 0
rel = 0
cad = 0
ope = 0

If ObjDictStored Then

count = cint(Session("ObjDict").Count/6)
Response.Write count
for i = 0 to count -1
bMenu2 = False
bMenu3 = False

If Session("ObjDict")("dep"&i) = "" Then
Session("ObjDict")("dep"&i) = null
End If
If trim(Session("ObjDict")("menu"&i)&"") = "" Then
Session("ObjDict")("menu"&i) = null
Else
Session("ObjDict")("menu"&i) = cint(Session
("ObjDict")("menu"&i))
End If
If isNull(Session("ObjDict")("dep"&i)) Then

If obj_menu <> Session("ObjDict")("menu"&i) Then

esp = 45

If obj_menu <> 0 Then
response.write(" </table>"
& vbcrlf & "</div>")
End If

obj_menu = Session("ObjDict")("menu"&i)
bMenu2 = true
If obj_menu = 1 Then
Desc = "adm"
ini = 25
adm = 1
End If
If obj_menu = 2 Then
Desc = "rel"
ini = 45
rel = 1
End if
If obj_menu = 3 Then
Desc = "cad"
ini = 90
cad = 1
End if
If obj_menu = 4 Then
Desc = "ope"
ini = 125
ope = 1
End if

esp = esp + ini

End If

If bMenu2 Then
bMenu2 = False
%>

<!-- Menu de 2o. Nivel - <%=Desc%> -->
<div id="<%=Desc%>" style="position:absolute; left:455px; top:<%=ini%>px;
width:265px; z-index:6; visibility: hidden">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><img src="../imagens/barra.gif" width="317"
height="13"></td>
</tr>
</table>
<table width="119%" border="0" cellspacing="0" cellpadding="0">
<%
End if
If Session("ObjDict")("nmObj"&i) <> "" Then
link = "<a href='comum.asp?p=" & Session
("ObjDict")("nmObj"&i) & "&a=" & Session("ObjDict")("tpAcesso"&i) & "'
class='link'>" & Session("ObjDict")("dsObj"&i) & "</a>"
Else
link = "<a href='Javascript: showhideMenu
(" & Desc & "sub" & Session("ObjDict")("idObj"&i) & ")' class='link'>" &
Session("ObjDict")("dsObj"&i) & "</a> <img src='../imagens/setinha.gif'
width='9' height='10'>"
End if
esp = esp + 12
if not IsNull(Session("ObjDict")("tpacesso"&i))
Then
%>
<tr>
<td width="36%"> </td>
<td width="59%"><%=link%></td>
<td width="5%"> </td>
</tr>
<%
End if
Else

If dep <> Session("ObjDict")("dep"&i) Then

If trim(dep) <> "0" Then
response.write(" </table>"
& vbcrlf & "</div>")
End if

dep = Session("ObjDict")("dep"&i)
bMenu3 = True
End If

If bMenu3 Then

response.write(" </table>" & vbcrlf
& "</div>")
bMenu3 = False
mn = Desc & "sub" & Session("ObjDict")
("dep"&i)
%>

<!-- Menu de 3o. Nivel - <%=mn%> -->
<div id="<%=mn%>" style="position:absolute; left:570px; top:<%=esp%>px;
width:200px; height:70px; z-index:8; visibility: hidden">
  <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td><img src="../imagens/barra_seta.gif" width="174"
height="14"></td>
    </tr>
  </table>
  <table width="100%" border="0" cellspacing="0" cellpadding="0">
<%
End if
link = "<a href='comum.asp?p=" & Session("ObjDict")
("nmObj"&i) & "&a=" & Session("ObjDict")("tpAcesso"&i) & "' class='link'>"
& Session("ObjDict")("dsObj"&i) & "</a>"
%>
    <tr>
      <td width="10%"> </td>
      <td width="80%"><%=link%></td>
      <td width="10%"> </td>
    </tr>
<%
If i = count -1 Then
response.write(" </table>" & vbcrlf
& "</div>")
End If
End if

If i = count -1 Then
response.write(" </table>" & vbcrlf
& "</div>")
End If


Next

Else
Set rs = Server.CreateObject("ADODB.Recordset")
Set rs = obj.monta_menu(cstr(Request.ServerVariables("AUTH_USER")))
If not rs.EOF Then
Set Session("objDict") = Server.CreateObject
("Scripting.Dictionary")
i = 0
Do While not rs.EOF

bMenu2 = False
bMenu3 = False

If isNull(rs("dep")) Then

If obj_menu <> cint(rs("menu")) Then

esp = 45

If obj_menu <> 0 Then
response.write("
</table>" & vbcrlf & "</div>")
End If

obj_menu = cint(rs("menu"))
bMenu2 = true

If obj_menu = 1 Then
Desc = "adm"
ini = 25
adm = 1
End If
If obj_menu = 2 Then
Desc = "rel"
ini = 45
rel = 1
End if
If obj_menu = 3 Then
Desc = "cad"
ini = 90
cad = 1
End if
If obj_menu = 4 Then
Desc = "ope"
ini = 125
ope = 1
End if

esp = esp + ini

End If

If bMenu2 Then
bMenu2 = False
%>

<!-- Menu de 2o. Nivel - <%=Desc%> -->
<div id="<%=Desc%>" style="position:absolute; left:455px; top:<%
=ini%>px; width:265px; z-index:6; visibility: hidden">
<table width="100%" border="0" cellspacing="0"
cellpadding="0">
<tr>
<td><img src="../imagens/barra.gif"
width="317" height="13"></td>
</tr>
</table>
<table width="119%" border="0" cellspacing="0"
cellpadding="0">
<%
End if
If rs("nmObj") <> "" Then
link = "<a href='comum.asp?p=" & rs
("nmObj") & "&a=" & rs("tpAcesso") & "' class='link'>" & rs("dsObj")
& "</a>"
Else
link = "<a href='Javascript:
showhideMenu(" & Desc & "sub" & rs("idObj") & ")' class='link'>" & rs
("dsObj") & "</a> <img src='../imagens/setinha.gif' width='9' height='10'>"
End if
esp = esp + 12
if not IsNull(rs("tpacesso")) Then
%>
<tr>
<td width="36%"> </td>
<td width="59%"><%=link%></td>
<td width="5%"> </td>
</tr>
<%
End if
Else

If dep <> rs("dep") Then

If dep <> 0 Then
response.write("
</table>" & vbcrlf & "</div>")
End if

dep = rs("dep")
bMenu3 = True
End If

If bMenu3 Then
Dim mn
response.write(" </table>"
& vbcrlf & "</div>")
bMenu3 = False
mn = Desc & "sub" & rs("dep")
%>

<!-- Menu de 3o. Nivel - <%=mn%> -->
<div id="<%=mn%>" style="position:absolute; left:570px; top:<%=esp%
>px; width:200px; height:70px; z-index:8; visibility: hidden">
  <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td><img src="../imagens/barra_seta.gif" width="174"
height="14"></td>
    </tr>
  </table>
  <table width="100%" border="0" cellspacing="0" cellpadding="0">
<%
End if
link = "<a href='comum.asp?p=" & rs
("nmObj") & "&a=" & rs("tpAcesso") & "' class='link'>" & rs("dsObj")
& "</a>"
%>
    <tr>
      <td width="10%"> </td>
      <td width="80%"><%=link%></td>
      <td width="10%"> </td>
    </tr>
<%
If rs.EOF Then
response.write(" </table>"
& vbcrlf & "</div>")
End If
End if
Session("objDict").Add "dep"&i,cstr(trim(rs("dep")
&""))
Session("objDict").Add "menu"&i,cstr(trim(rs
("menu")&""))
Session("objDict").Add "nmObj"&i,cstr(trim(rs
("nmObj")&""))
Session("objDict").Add "dsObj"&i,cstr(trim(rs
("dsObj")&""))
Session("objDict").Add "tpAcesso"&i,cstr(trim(rs
("tpAcesso")&""))
Session("objDict").Add "idObj"&i,cstr(trim(rs
("idObj")&""))

i = i + 1
rs.MoveNext
If rs.EOF Then
response.write(" </table>" & vbcrlf
& "</div>")
End If
Loop
Session("ObjDictStored") = true
End if

End IF

%>

<!-- Layer para o botão de fechar janela -->
<div id="fechar" style="position:absolute; left:5px; top:4px; width:42px;
height:28px; z-index:2">
                        <a href="JavaScript:fechar()"
onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage
('Image33','','../imagens/fechar_hover2.gif',1)"><img name="Image33"
border="0" src="../imagens/fechar_hover.gif" width="38" height="27"></a>
</div>

<!-- Layer para os itens do menu do sistema -->
<div id="menusys"  style="position:absolute; left:326px; top:18px;
width:149px; height:130px; z-index:3">
<a href="#"><img name="Image1" border="0"
src="../imagens/admin1.gif" width="137" height="29" onMouseOver="<%if
adm = 1 then response.write("showhideMenu(adm)")%>;MM_swapImage
('Image1','','../imagens/admin2.gif',1);"
onMouseOut="MM_swapImgRestore();"></a>
<br><a href="#"><img name="Image2" border="0"
src="../imagens/relat1.gif" width="137" height="30" onMouseOver="<%if
rel = 1 then response.write("showhideMenu(rel)") else response.write
("showhideMenu(mns)") End if%>;MM_swapImage
('Image2','','../imagens/relat2.gif',1);"
onMouseOut="MM_swapImgRestore()"></a>
<br><a href="#"><img name="Image3" border="0"
src="../imagens/cad1.gif" width="137" height="27"
onMouseOver="<%if cad = 1 then response.write("showhideMenu(cad)")%
>;MM_swapImage('Image3','','../imagens/cad2.gif',1);"
onMouseOut="MM_swapImgRestore()"></a>
<br><a href="#"><img name="Image4" border="0"
src="../imagens/op1.gif" width="137" height="32"
onMouseOver="<%if ope = 1 then response.write("showhideMenu(ope)")%
>;MM_swapImage('Image4','','../imagens/op2.gif',1);"
onMouseOut="MM_swapImgRestore()"></a>
</div>

<!-- Layer para as ferramentas -->
<div id="tools" style="position:absolute; left:40px; top:132px;
width:285px; height:31px; z-index:4">
<a href="#" onMouseOut="MM_swapImgRestore()"
onMouseOver="MM_swapImage('Image5','','../imagens/reports2.gif',1)"><img
name="Image5" border="0" src="../imagens/reports.gif" width="79"
height="32"></a>
<a href="#" onMouseOut="MM_swapImgRestore()"
onMouseOver="MM_swapImage('Image6','','../imagens/monitor2.gif',1)"><img
name="Image6" border="0" src="../imagens/monitor.gif" width="103"
height="32"></a>
<a href="#" onMouseOut="MM_swapImgRestore()"
onMouseOver="MM_swapImage('Image7','','../imagens/analyser2.gif',1)"><img
name="Image7" border="0" src="../imagens/analyser.gif" width="83"
height="32"></a>
</div>

<!-- Layer para os itens do rodapé -->
<div id="footer" style="position:absolute; left:250px; top:544px;
width:165px; height:32px; z-index:5">
<a href="#" onMouseOut="MM_swapImgRestore()"
onMouseOver="MM_swapImage
('Image8','','../imagens/faleconosco2.gif',1)"><img name="Image8"
border="0" src="../imagens/faleconosco1.gif" width="72" height="29"></a>
<a href="#" onMouseOut="MM_swapImgRestore()"
onMouseOver="MM_swapImage('Image9','','../imagens/help2.gif',1)"><img
name="Image9" border="0" src="../imagens/help1.gif" width="36"
height="29"></a>
<a href="#" onMouseOut="MM_swapImgRestore()"
onMouseOver="MM_swapImage('Image10','','../imagens/sobre2.gif',1)"><img
name="Image10" border="0" src="../imagens/sobre.gif" width="38"
height="29"></a>
</div>

<!-- Layer para as mensagens -->
<div id="message" style="position:absolute; left:40px; top:168px;
width:500px; height:15px; z-index:6" class="texto">
<img src="../imagens/setinha.gif" width="9" height="10">
Espaço para texto de script, que irá ter scroll.
</div>

<div id="mns" style="position:absolute; left:320px; top:10px; with:455px;
height:480px; z-index:1" class="texto" onmouseout="showhideMenu
(mns)"></div>

</body>
</html>
<!--#include file="ic_conexao_close.asp"-->

  Return to Index