0

I've been storing things like user role, name etc.. in a session to pass each page and I notice the project i'm updating has been doing this by fetching the values from a SQL Server database on every pageload.

My Question is, which one is better practice to do this? On Session it's a bit annoying because I have to do many null checks unless i create a class to act as the user container and fetching data from SQL server every pageload seems like a big load on performance. Should I just keep doing it the session way? Seems more simple and more practical.

EDIT.

There's also this called membership in ASP.NET to store user role and set it on web.config but I haven't digged into it much

1 Answer 1

1

On each page load, usually you need to get data from the database – I do not see why this is an issue on performance in general.

On an asp.net application, you may have many pools that runs it. This is mean that you have different application that each one can serve your user at any time.

Moreover, each of this application have different memory, different static data, and they are not communicate together.

The one way this different asp.net application to communicate is with the use of a file, like a database.

The other way is to use some common service that they reference – and there is a service for session.

Sign up to request clarification or add additional context in comments.

7 Comments

Makes sense, but for example, if i just need user role on every page, i could just use something like ASP net membership roles instead of a database call?
@JFC asp net membership also use database.
@JFC generally speaking, make your page, make your best, and later check for the speeding. There are a lot of tricks for how to make a page load fast... too many. On the database part, you need to use a fast orm library - and make a good design
I ended up just storing the role in the formvalidationticket which stores it in cookies so i don't need database unless I later i decide to read roles from SQL. Either way, it doesn't change anything if i need some other user details like the Name or E-mail of the user which i'll have to store them in session or make the database call when i need it
@JFC I think yes, store as little as possible on cookies
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.