MVC - same URL, several types

Is it considered bad practice to have multiple views for the same URL in MVC based on different user roles? For example: http://www.domain.com/ViewProductID/123 will show the "normal" product page for the average user, and it will show the "improved" (product statistics, the ability to edit the title, etc.) so that someone logs in to the system as an administrator.

If this is bad practice, why? If everything is in order, what is the best way to implement it? 2 separate templates or 1 template scattered with if..sse?

Thanks!

+6
model-view-controller
source share
4 answers

I think it’s fine to change the context based view; This happens all the time. If you do if .. else or several aspx files really depend on how much they differ. A couple of alternatives:

1) use Html.RenderAction to call AdminController actions to embed material, AdminController can return empty results if the user is not an administrator

or better:

2) use a different main page based on the role / status of the user. That way, you can pull out the logic to install the wizard in an actionfilter like him, and do it once, but apply it wherever it makes sense. Just make sure alternate master pages are compatible with views in terms of the content contentplaceplaceId.

+2
source share

In my opinion, it’s good to have the same URL for users and administrators. the real question is usability for your users. Does it affect them? Many sites that use MVC provide additional content or links depending on the level of authorization.

What framework and language do you use? You may not need a completely different template if you have something like partial views available to you.

+1
source share

If the pages do not differ much (i.e. they show the same data, possibly more for admins), then I would say that all the codes are in one file. If possible, use a role-based ability management system so you can ask questions such as:

if can? :create, Users do ... else ... end 

Then you configure your abilities so that administrators and managers can create users. Thus, you do not need to worry about who the user is, only what the user is allowed to do.

+1
source share

Basically you are talking about permissions leading to different pages, which is very important. Think of the default landing page on Facebook for 2 different people.

The implementation is the same as for any other: combine common elements where you can reuse. Simple differences may just come in if ... other and more complex differences relate to different patterns.

+1
source share

All Articles