473,802 Members | 1,996 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Any suggestion for ASP.NET caching mechanism on this?

B
Hi,

I'm working on a site where the user must log in before they see the
home page.

When the user logs in, I retrieve their role from the database, store
it in a Session object and redirect to the homepage. The home page
contains a navigation menu (user control) which displays links
available to the user based on their role. The navigation menu/links
are generated from the database.

To minimize database calls, once the user logs in I'd like to
effectively cache the navigation menu user control for the duration of
that user's session. Does anyone have any idea how to do this?

I've had a look at setting Duration on @OutputCache but this causes
problems if a user logs out, and another user logs in with a different
role: the new user sees the old user's navigation menu.

Would Application level variables be more appropriate in this
situation? I have to say that I don't have much experience of caching
in ASP.NET so any help would be appreciated.

Thanks,

B

Jan 25 '06 #1
4 1594
This article may help you decide on what type of caching to use.
http://msdn.microsoft.com/msdnmag/is...e/default.aspx

"B" <br************ *@yahoo.co.uk> wrote in message
news:11******** **************@ g43g2000cwa.goo glegroups.com.. .
Hi,

I'm working on a site where the user must log in before they see the
home page.

When the user logs in, I retrieve their role from the database, store
it in a Session object and redirect to the homepage. The home page
contains a navigation menu (user control) which displays links
available to the user based on their role. The navigation menu/links
are generated from the database.

To minimize database calls, once the user logs in I'd like to
effectively cache the navigation menu user control for the duration of
that user's session. Does anyone have any idea how to do this?

I've had a look at setting Duration on @OutputCache but this causes
problems if a user logs out, and another user logs in with a different
role: the new user sees the old user's navigation menu.

Would Application level variables be more appropriate in this
situation? I have to say that I don't have much experience of caching
in ASP.NET so any help would be appreciated.

Thanks,

B

Jan 25 '06 #2
B,
Suggestions:
1) Consider using Forms Authentication against your database, since it has
much of what you describe (roles, for example) already built-in.
2) To cache user-specific permissions relating to the display of a
navigation menu, you should consider setting up the menu with a public Role
property which determines what it displays. You can then use the
Page.User.IsInR ole("admin") method of the authenticated user and you won't
need to cache anything.

Setting OutputCache on the control won't help you in this situation since
the control needs to be displaying specific to the authenticated user.
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"B" wrote:
Hi,

I'm working on a site where the user must log in before they see the
home page.

When the user logs in, I retrieve their role from the database, store
it in a Session object and redirect to the homepage. The home page
contains a navigation menu (user control) which displays links
available to the user based on their role. The navigation menu/links
are generated from the database.

To minimize database calls, once the user logs in I'd like to
effectively cache the navigation menu user control for the duration of
that user's session. Does anyone have any idea how to do this?

I've had a look at setting Duration on @OutputCache but this causes
problems if a user logs out, and another user logs in with a different
role: the new user sees the old user's navigation menu.

Would Application level variables be more appropriate in this
situation? I have to say that I don't have much experience of caching
in ASP.NET so any help would be appreciated.

Thanks,

B

Jan 25 '06 #3
Try saving the user-specific menu items in a session variable as XML.

"B" wrote:
Hi,

I'm working on a site where the user must log in before they see the
home page.

When the user logs in, I retrieve their role from the database, store
it in a Session object and redirect to the homepage. The home page
contains a navigation menu (user control) which displays links
available to the user based on their role. The navigation menu/links
are generated from the database.

To minimize database calls, once the user logs in I'd like to
effectively cache the navigation menu user control for the duration of
that user's session. Does anyone have any idea how to do this?

I've had a look at setting Duration on @OutputCache but this causes
problems if a user logs out, and another user logs in with a different
role: the new user sees the old user's navigation menu.

Would Application level variables be more appropriate in this
situation? I have to say that I don't have much experience of caching
in ASP.NET so any help would be appreciated.

Thanks,

B

Jan 25 '06 #4

Personally, I would think about separating the Roles collection, from the
Control, and cache the Roles first.

You could implement your own IPrincipal object.

When the user logs on correctly, you create, and cache the IPrincipal
object.

The User Control code looks like this:

{

if (null!= Session["MYKEY"])
{
MyPrincipal princ = Session["MYKEY"];

hyperlinkButton 1.Visible = princ.IsInRole( "ManageUser s");
hyperlinkButton 2.Visible = princ.IsInRole( "ManageDept s");
hyperlinkButton 3.Visible = princ.IsInRole( "ManageResource s");

}
else
{
// no items enabled ... show the login link
hyperlinkButton 4.Text = "You need to login";
hyperlinkButton 4.Visible = true;

}

}
IPrincipal implementation takes a little work, but its not rocket science.
You could then have a BusinessLogic object which authenticates a User like
this:
public void MyPrincipal BusinessLogic.U sers.Authentica teUser (string
userName, string password)

{

//check your database, and then populate your implementation of
IPrincipal with the roles.
ArrayList al = new ArrayList();
al.Add("Manager Users");
al.Add("ManageD epts");
// i am not adding ManageResources

return new MyPrincipal ( new MyIdentity("bri an") , al );

//you need to write a MyIdentity (implements IIdentity class also, which is
basically your name.

}
MyPrincipal looks something like this:
public class MyPrincipal : IPrincipal
{
private MyIdentity m_id;
private ArrayList m_roles;

public MyPrincipal (IIdentity id , ArrayList roles)
{
this.m_id = id;
this.m_roles = roles;
}

public bool IsInRole(string role)
{

//check the m_roles to see if it contains the role
return true; //stub return value

}
}

This way, you can reuse your MyPrincipal object, whereever you need it.

You can then try to cache the UserControl using traditional UserControl
methods.

But you haven't tied together your MyPrincipal , making a looser coupling
between the roles a user has, and the presentation of those roles.

...

IPrincipal and IIdentity are not that hard, it takes a little used to using.



"B" <brian_is_onlin e@yahoo

..co.uk> wrote in message
news:11******** **************@ g43g2000cwa.goo glegroups.com.. .
Hi,

I'm working on a site where the user must log in before they see the
home page.

When the user logs in, I retrieve their role from the database, store
it in a Session object and redirect to the homepage. The home page
contains a navigation menu (user control) which displays links
available to the user based on their role. The navigation menu/links
are generated from the database.

To minimize database calls, once the user logs in I'd like to
effectively cache the navigation menu user control for the duration of
that user's session. Does anyone have any idea how to do this?

I've had a look at setting Duration on @OutputCache but this causes
problems if a user logs out, and another user logs in with a different
role: the new user sees the old user's navigation menu.

Would Application level variables be more appropriate in this
situation? I have to say that I don't have much experience of caching
in ASP.NET so any help would be appreciated.

Thanks,

B

Jan 25 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1698
by: Shabam | last post by:
I need to implement a caching mechanism for my script URLs. Instead of www.domain.com/script.cgi?id=1234 , which the browser will obviously not cache, I want the URL to be something like www.domain.com/1234 or www.domain.com/1234.htm instead. This way the browser will cache the page. I have two concerns: 1) Is this possible without rewriting the url? If so how? 2) The result page will be different for different users. Will this...
6
1918
by: Matthew Bates | last post by:
Hi, I've been using PHP for a while now and I'm beginning to migrate to PHP5. So far, I'm impressed. I need to develop an admin application to enable users to update a website that is built on a MySQL database. In most cases, I'd simply develop an application to manipulate the database but as the website is updated fairly infrequently, I am considering a number of further options instead to alleviate server load.
2
2451
by: Michael G | last post by:
Can the browser back button or browser caching be turned on or off via php? Thanks, Mike ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups ----= East and West-Coast Server Farms - Total Privacy via Encryption =----
2
3106
by: Steve W | last post by:
I have an ASP.NET app that calls into some VB.NET components. It passes in the current application's cache (HttpContext.Current.Cache). These VB.NET components also get called by a non-ASP.NET application (in this case a VB.NET windows service). I'd like to create something like the cache in this service to hold application-wide information (like database connection strings) and then pass that into the components. As a test, I tried...
5
7859
by: Raj | last post by:
What is the purpose of file system caching while creating a tablespace? Memory on the test server gets used up pretty quickly after a user executes a complex query(database is already activated), after some investgation i found out that most of it being consumed by filesystem caching... thanks to Liam and Phil Sherman for their valuable suggestions. Is it safe to turn off filesystem caching on every tablespaceon the server(i.e. DIO) ??...
2
2186
by: aptenodytesforsteri | last post by:
I have an ASP.NET 2.0 application I've localized to English, French, German, and Italian. I used resource (.resx) files. Most of the site is static content, easily 90% of it, so I thought output caching would be useful. I implemented output caching at 60 seconds.
4
2186
by: Henrik Dahl | last post by:
Hello! In my application I have a need for using a regular expression now and then. Often the same regular expression must be used multiple times. For performance reasons I use the RegexOptions.Compiled when I instantiate it. It must be obvious that it takes some time to instantiate such an object. My question is, does the Regex instantiation somehow deal with some caching internally so instantiating a Regex object multiple times...
10
1107
by: Peter | last post by:
I have Windows Service application which creates reports. It's a multithreaded application which scans database every several seconds and retrieves records from a database and than spans a new thread for each record which creates a report. I run this application on 3 different servers and each server does a specific type of records. What I would like to do is to have all servers processing any type of record, but I want only one program...
1
1513
by: Mateusz Viste | last post by:
В Четверг 16 октября 2008 17:21, sasuke писал: There is many requests indeed, but it's rather normal - Steve has put online various weird stuff which needs to be loaded :-) As for the binary clock, my Firefox sends the following commands: GET /stephen.joung/binclock_8.jpg HTTP/1.1 GET /stephen.joung/binclock_4.jpg HTTP/1.1 GET /stephen.joung/binclock_2.jpg HTTP/1.1 GET /stephen.joung/binclock_1.jpg HTTP/1.1
0
9699
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
10304
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10285
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10063
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6838
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4270
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3792
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2966
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.