By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,505 Members | 1,034 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,505 IT Pros & Developers. It's quick & easy.

Retrive User Control from Cache

P: n/a
I have created a custom user control which creates a ASPxMenu ( Same
fucntion as standard menu control) from data retreved from a webservice
(Reporting Services) which deals with user access. This process is
slow. And as the menu object will not change in a session I am trying
to cache the menu with the session user as the key. The problem is that
I can not retreve the menu object after the first request. The menu
items are resident in the cahce but can not display the menu. Can any
one help? problibly be a simple ansewer , syntax maybe.

sudo code:
if cache is emtpy then
populate menu
else
menu = cache

Full Code: custom control ascx file

Imports DevExpress.Web.ASPxMenu
Imports System.Web.UI

Partial Class WebUserControl
Inherits System.Web.UI.UserControl

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

If
Cache(System.Net.CredentialCache.DefaultNetworkCre dentials.ToString) Is
Nothing Then

'Dim ASPxMenu1 As ASPxMenu = MENU
Dim service As aureports.ReportingService = New
aureports.ReportingService

service.Url =
"http://localhost/reportserver/reportservice.asmx"
'Me.service.Credentials =
System.Net.CredentialCache.DefaultNetworkCredentia ls
service.Credentials = New
System.Net.NetworkCredential("test", "test")

ASPxMenu1.Items.Clear()
ASPxMenu1.Items.Add("Reports")
ASPxMenu1.Items.Add("Services")
ASPxMenu1.Items.Add("Links")
ASPxMenu1.Items.Add("Help")

Dim items() As aureports.CatalogItem =
service.ListChildren("/", False)
'Ask how to sort the catalogitem list
For Each item As aureports.CatalogItem In items

If item.Type = aureports.ItemTypeEnum.Folder And Not
(item.Name Like "*_aspx") Then

Dim mitem As New
DevExpress.Web.ASPxMenu.MenuItem(item.Name, item.Path)

ASPxMenu1.Items.Item(ASPxMenu1.Items.IndexOfText(" Reports")).Items.Add(mitem)
folder(item, mitem, service)

ElseIf item.Type = aureports.ItemTypeEnum.Report And
Not (item.Name Like "*_aspx") And item.Hidden = False Then

Dim mitem As New
DevExpress.Web.ASPxMenu.MenuItem(item.Name)

ASPxMenu1.Items.Item(ASPxMenu1.Items.IndexOfText(" Reports")).Items.Add(mitem)

ElseIf item.Type = aureports.ItemTypeEnum.Folder And
item.Name Like "*_aspx" Then

Dim words() As String = Split(item.Name, "_aspx")
Dim mitem As New
DevExpress.Web.ASPxMenu.MenuItem(words(0))

ASPxMenu1.Items.Item(ASPxMenu1.Items.IndexOfText(" Services")).Items.Add(mitem)
folder(item, mitem, service)

End If

Next

Cache.Insert(System.Net.CredentialCache.DefaultNet workCredentials.ToString,
ASPxMenu1)
Else
ASPxMenu1 =
(CType(Cache.Get(System.Net.CredentialCache.Defaul tNetworkCredentials.ToString),
ASPxMenu))
End If
End Sub

Public Shared Sub folder(ByVal item As aureports.CatalogItem, ByVal
menu As DevExpress.Web.ASPxMenu.MenuItem, ByVal service As
aureports.ReportingService)

Dim items() As aureports.CatalogItem =
service.ListChildren(item.Path, False)

For Each item2 As aureports.CatalogItem In items
Dim words() As String
words = Split(item2.Name, "_aspx")

Dim itmMenuItem2 As New
DevExpress.Web.ASPxMenu.MenuItem(words(0), "", "", item2.Description)

If item2.Type = aureports.ItemTypeEnum.Folder Then
menu.Items.Add(itmMenuItem2)
folder(item2, itmMenuItem2, service)
ElseIf item2.Type = aureports.ItemTypeEnum.Report And
item2.Hidden = False Then
menu.Items.Add(itmMenuItem2)
ElseIf words.Length 1 Then
menu.Items.Add(itmMenuItem2)
End If

Next

End Sub

End Class

Nov 1 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
You have a couple of issues that could be improved:

1) use a simpler key for the Cache item - say, the SessionId, which should
not change during the user's session.
2) instead of caching the entire MenuControl, cache only the datasource, and
use that to rebuild your menu.

Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"po*******@hotmail.com" wrote:
I have created a custom user control which creates a ASPxMenu ( Same
fucntion as standard menu control) from data retreved from a webservice
(Reporting Services) which deals with user access. This process is
slow. And as the menu object will not change in a session I am trying
to cache the menu with the session user as the key. The problem is that
I can not retreve the menu object after the first request. The menu
items are resident in the cahce but can not display the menu. Can any
one help? problibly be a simple ansewer , syntax maybe.

sudo code:
if cache is emtpy then
populate menu
else
menu = cache

Full Code: custom control ascx file

Imports DevExpress.Web.ASPxMenu
Imports System.Web.UI

Partial Class WebUserControl
Inherits System.Web.UI.UserControl

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

If
Cache(System.Net.CredentialCache.DefaultNetworkCre dentials.ToString) Is
Nothing Then

'Dim ASPxMenu1 As ASPxMenu = MENU
Dim service As aureports.ReportingService = New
aureports.ReportingService

service.Url =
"http://localhost/reportserver/reportservice.asmx"
'Me.service.Credentials =
System.Net.CredentialCache.DefaultNetworkCredentia ls
service.Credentials = New
System.Net.NetworkCredential("test", "test")

ASPxMenu1.Items.Clear()
ASPxMenu1.Items.Add("Reports")
ASPxMenu1.Items.Add("Services")
ASPxMenu1.Items.Add("Links")
ASPxMenu1.Items.Add("Help")

Dim items() As aureports.CatalogItem =
service.ListChildren("/", False)
'Ask how to sort the catalogitem list
For Each item As aureports.CatalogItem In items

If item.Type = aureports.ItemTypeEnum.Folder And Not
(item.Name Like "*_aspx") Then

Dim mitem As New
DevExpress.Web.ASPxMenu.MenuItem(item.Name, item.Path)

ASPxMenu1.Items.Item(ASPxMenu1.Items.IndexOfText(" Reports")).Items.Add(mitem)
folder(item, mitem, service)

ElseIf item.Type = aureports.ItemTypeEnum.Report And
Not (item.Name Like "*_aspx") And item.Hidden = False Then

Dim mitem As New
DevExpress.Web.ASPxMenu.MenuItem(item.Name)

ASPxMenu1.Items.Item(ASPxMenu1.Items.IndexOfText(" Reports")).Items.Add(mitem)

ElseIf item.Type = aureports.ItemTypeEnum.Folder And
item.Name Like "*_aspx" Then

Dim words() As String = Split(item.Name, "_aspx")
Dim mitem As New
DevExpress.Web.ASPxMenu.MenuItem(words(0))

ASPxMenu1.Items.Item(ASPxMenu1.Items.IndexOfText(" Services")).Items.Add(mitem)
folder(item, mitem, service)

End If

Next

Cache.Insert(System.Net.CredentialCache.DefaultNet workCredentials.ToString,
ASPxMenu1)
Else
ASPxMenu1 =
(CType(Cache.Get(System.Net.CredentialCache.Defaul tNetworkCredentials.ToString),
ASPxMenu))
End If
End Sub

Public Shared Sub folder(ByVal item As aureports.CatalogItem, ByVal
menu As DevExpress.Web.ASPxMenu.MenuItem, ByVal service As
aureports.ReportingService)

Dim items() As aureports.CatalogItem =
service.ListChildren(item.Path, False)

For Each item2 As aureports.CatalogItem In items
Dim words() As String
words = Split(item2.Name, "_aspx")

Dim itmMenuItem2 As New
DevExpress.Web.ASPxMenu.MenuItem(words(0), "", "", item2.Description)

If item2.Type = aureports.ItemTypeEnum.Folder Then
menu.Items.Add(itmMenuItem2)
folder(item2, itmMenuItem2, service)
ElseIf item2.Type = aureports.ItemTypeEnum.Report And
item2.Hidden = False Then
menu.Items.Add(itmMenuItem2)
ElseIf words.Length 1 Then
menu.Items.Add(itmMenuItem2)
End If

Next

End Sub

End Class

Nov 1 '06 #2

P: n/a
Thanks Peter I'll use the session id.

Going to have to think about the menu a little more. as the datasource
is more complicated than just dataset. Ideally I would store an items
collection for the menu but have not found the methods to do this.
Would this not be working due the complexity of the object ?

Peter wrote:
You have a couple of issues that could be improved:

1) use a simpler key for the Cache item - say, the SessionId, which should
not change during the user's session.
2) instead of caching the entire MenuControl, cache only the datasource, and
use that to rebuild your menu.

Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"po*******@hotmail.com" wrote:
I have created a custom user control which creates a ASPxMenu ( Same
fucntion as standard menu control) from data retreved from a webservice
(Reporting Services) which deals with user access. This process is
slow. And as the menu object will not change in a session I am trying
to cache the menu with the session user as the key. The problem is that
I can not retreve the menu object after the first request. The menu
items are resident in the cahce but can not display the menu. Can any
one help? problibly be a simple ansewer , syntax maybe.

sudo code:
if cache is emtpy then
populate menu
else
menu = cache

Full Code: custom control ascx file

Imports DevExpress.Web.ASPxMenu
Imports System.Web.UI

Partial Class WebUserControl
Inherits System.Web.UI.UserControl

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

If
Cache(System.Net.CredentialCache.DefaultNetworkCre dentials.ToString) Is
Nothing Then

'Dim ASPxMenu1 As ASPxMenu = MENU
Dim service As aureports.ReportingService = New
aureports.ReportingService

service.Url =
"http://localhost/reportserver/reportservice.asmx"
'Me.service.Credentials =
System.Net.CredentialCache.DefaultNetworkCredentia ls
service.Credentials = New
System.Net.NetworkCredential("test", "test")

ASPxMenu1.Items.Clear()
ASPxMenu1.Items.Add("Reports")
ASPxMenu1.Items.Add("Services")
ASPxMenu1.Items.Add("Links")
ASPxMenu1.Items.Add("Help")

Dim items() As aureports.CatalogItem =
service.ListChildren("/", False)
'Ask how to sort the catalogitem list
For Each item As aureports.CatalogItem In items

If item.Type = aureports.ItemTypeEnum.Folder And Not
(item.Name Like "*_aspx") Then

Dim mitem As New
DevExpress.Web.ASPxMenu.MenuItem(item.Name, item.Path)

ASPxMenu1.Items.Item(ASPxMenu1.Items.IndexOfText(" Reports")).Items.Add(mitem)
folder(item, mitem, service)

ElseIf item.Type = aureports.ItemTypeEnum.Report And
Not (item.Name Like "*_aspx") And item.Hidden = False Then

Dim mitem As New
DevExpress.Web.ASPxMenu.MenuItem(item.Name)

ASPxMenu1.Items.Item(ASPxMenu1.Items.IndexOfText(" Reports")).Items.Add(mitem)

ElseIf item.Type = aureports.ItemTypeEnum.Folder And
item.Name Like "*_aspx" Then

Dim words() As String = Split(item.Name, "_aspx")
Dim mitem As New
DevExpress.Web.ASPxMenu.MenuItem(words(0))

ASPxMenu1.Items.Item(ASPxMenu1.Items.IndexOfText(" Services")).Items.Add(mitem)
folder(item, mitem, service)

End If

Next

Cache.Insert(System.Net.CredentialCache.DefaultNet workCredentials.ToString,
ASPxMenu1)
Else
ASPxMenu1 =
(CType(Cache.Get(System.Net.CredentialCache.Defaul tNetworkCredentials.ToString),
ASPxMenu))
End If
End Sub

Public Shared Sub folder(ByVal item As aureports.CatalogItem, ByVal
menu As DevExpress.Web.ASPxMenu.MenuItem, ByVal service As
aureports.ReportingService)

Dim items() As aureports.CatalogItem =
service.ListChildren(item.Path, False)

For Each item2 As aureports.CatalogItem In items
Dim words() As String
words = Split(item2.Name, "_aspx")

Dim itmMenuItem2 As New
DevExpress.Web.ASPxMenu.MenuItem(words(0), "", "", item2.Description)

If item2.Type = aureports.ItemTypeEnum.Folder Then
menu.Items.Add(itmMenuItem2)
folder(item2, itmMenuItem2, service)
ElseIf item2.Type = aureports.ItemTypeEnum.Report And
item2.Hidden = False Then
menu.Items.Add(itmMenuItem2)
ElseIf words.Length 1 Then
menu.Items.Add(itmMenuItem2)
End If

Next

End Sub

End Class
Nov 1 '06 #3

P: n/a
If the object is serializable, you should be able to store it in Cache,
Session, Application state, etc.

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"po*******@hotmail.com" wrote:
Thanks Peter I'll use the session id.

Going to have to think about the menu a little more. as the datasource
is more complicated than just dataset. Ideally I would store an items
collection for the menu but have not found the methods to do this.
Would this not be working due the complexity of the object ?

Peter wrote:
You have a couple of issues that could be improved:

1) use a simpler key for the Cache item - say, the SessionId, which should
not change during the user's session.
2) instead of caching the entire MenuControl, cache only the datasource, and
use that to rebuild your menu.

Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"po*******@hotmail.com" wrote:
I have created a custom user control which creates a ASPxMenu ( Same
fucntion as standard menu control) from data retreved from a webservice
(Reporting Services) which deals with user access. This process is
slow. And as the menu object will not change in a session I am trying
to cache the menu with the session user as the key. The problem is that
I can not retreve the menu object after the first request. The menu
items are resident in the cahce but can not display the menu. Can any
one help? problibly be a simple ansewer , syntax maybe.
>
sudo code:
>
>
if cache is emtpy then
populate menu
else
menu = cache
>
>
>
Full Code: custom control ascx file
>
Imports DevExpress.Web.ASPxMenu
Imports System.Web.UI
>
Partial Class WebUserControl
Inherits System.Web.UI.UserControl
>
>
>
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
>
>
>
If
Cache(System.Net.CredentialCache.DefaultNetworkCre dentials.ToString) Is
Nothing Then
>
'Dim ASPxMenu1 As ASPxMenu = MENU
>
>
Dim service As aureports.ReportingService = New
aureports.ReportingService
>
service.Url =
"http://localhost/reportserver/reportservice.asmx"
'Me.service.Credentials =
System.Net.CredentialCache.DefaultNetworkCredentia ls
service.Credentials = New
System.Net.NetworkCredential("test", "test")
>
ASPxMenu1.Items.Clear()
ASPxMenu1.Items.Add("Reports")
ASPxMenu1.Items.Add("Services")
ASPxMenu1.Items.Add("Links")
ASPxMenu1.Items.Add("Help")
>
Dim items() As aureports.CatalogItem =
service.ListChildren("/", False)
'Ask how to sort the catalogitem list
For Each item As aureports.CatalogItem In items
>
If item.Type = aureports.ItemTypeEnum.Folder And Not
(item.Name Like "*_aspx") Then
>
Dim mitem As New
DevExpress.Web.ASPxMenu.MenuItem(item.Name, item.Path)
>
ASPxMenu1.Items.Item(ASPxMenu1.Items.IndexOfText(" Reports")).Items.Add(mitem)
folder(item, mitem, service)
>
ElseIf item.Type = aureports.ItemTypeEnum.Report And
Not (item.Name Like "*_aspx") And item.Hidden = False Then
>
Dim mitem As New
DevExpress.Web.ASPxMenu.MenuItem(item.Name)
>
ASPxMenu1.Items.Item(ASPxMenu1.Items.IndexOfText(" Reports")).Items.Add(mitem)
>
ElseIf item.Type = aureports.ItemTypeEnum.Folder And
item.Name Like "*_aspx" Then
>
Dim words() As String = Split(item.Name, "_aspx")
Dim mitem As New
DevExpress.Web.ASPxMenu.MenuItem(words(0))
>
ASPxMenu1.Items.Item(ASPxMenu1.Items.IndexOfText(" Services")).Items.Add(mitem)
folder(item, mitem, service)
>
End If
>
Next
>
Cache.Insert(System.Net.CredentialCache.DefaultNet workCredentials.ToString,
ASPxMenu1)
Else
>
>
ASPxMenu1 =
(CType(Cache.Get(System.Net.CredentialCache.Defaul tNetworkCredentials.ToString),
ASPxMenu))
>
>
End If
End Sub
>
Public Shared Sub folder(ByVal item As aureports.CatalogItem, ByVal
menu As DevExpress.Web.ASPxMenu.MenuItem, ByVal service As
aureports.ReportingService)
>
Dim items() As aureports.CatalogItem =
service.ListChildren(item.Path, False)
>
For Each item2 As aureports.CatalogItem In items
Dim words() As String
words = Split(item2.Name, "_aspx")
>
Dim itmMenuItem2 As New
DevExpress.Web.ASPxMenu.MenuItem(words(0), "", "", item2.Description)
>
If item2.Type = aureports.ItemTypeEnum.Folder Then
menu.Items.Add(itmMenuItem2)
folder(item2, itmMenuItem2, service)
ElseIf item2.Type = aureports.ItemTypeEnum.Report And
item2.Hidden = False Then
menu.Items.Add(itmMenuItem2)
ElseIf words.Length 1 Then
menu.Items.Add(itmMenuItem2)
End If
>
Next
>
End Sub
>
End Class
>
>

Nov 1 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.