PDA

View Full Version : How to check user privilege in MVC



ragecf
2 Jul 2013, 10:38 PM
Hi,

I have a question about checking user privilege.

Usually we should check user's privilege before user do any operation, such as user's group, login or not.

How to check these condition in MVC? Define a global function, then call it in related event handler?

I'm confused and have no idea. Anyone can provide an example?

Thanks.

existdissolve
3 Jul 2013, 7:16 PM
Hi,

I have a question about checking user privilege.

Usually we should check user's privilege before user do any operation, such as user's group, login or not.

How to check these condition in MVC? Define a global function, then call it in related event handler?

I'm confused and have no idea. Anyone can provide an example?

Thanks.

As always, it depends on the needs and structure of your app.

For example, you could take an approach where you only render components and other sections of the app that the logged in user has access permissions to.

Alternatively, you could render everything, and run checks before the relevant bit of functionality occur to see if they have permission.

I tend to retrieve permissions when the user logs on, and then store those permissions in the application. Then, when I need to do a check later on, I can simply interrogate the permissions that I have already saved, and decide what needs to happen next.

ragecf
3 Jul 2013, 11:45 PM
Thank you very much.

Now I used the solution 2 and saved user's permissions in cookie.

But I'm not a professional web UI developer, so I want to look some source code especially MVC code.