In my projects I always fetch roles from DB and store them in a session variable, then to check If a user has access to admin pages I just check the session.
Let's consider I use a private hosting what is the drawbacks of this approach?
|
|
|||||
|
|
Let's say a non-admin user edits their session cookie and changes You should give each user a session token like You also probably want to have it be an HTTP only (not editable by javascript) and Secure cookie (only set via https to prevent MITM). EDIT: http is a stateless protocol. Meaning that each http request coming to your server starts over from scratch; the web server isn't aware if you've accessed this page for the first time or are continuing a multi-page visit to the site. The basic way to create a session is to have some identifying variable get passed back to the webserver with each request; say through a hidden GET/POST variable, a changed URL, or more typically a cookie. A cookie could be set in an HTTP response from a webserver like:
and then when you make your next request to the webserver:
Note that since the user has full control of their web browser, you can't really trust the variables they are sending back. E.g., they could change |
|||||||||||||
|
|
A non authorized user should be stopped way before a call is made to populate the session details. You would be authenticating and authorizing the user in AuthenticateRequest & AuthorizeRequest events which are triggered before AcquireRequestState event. So, if the user is not authorized to view a resource, the rest of the events will not happen and hence we can avoid the load on DB or other resources. The life cycle is depicted at Remarks Section of HttpApplication Class in MSDN |
|||
|
|