Is it considered bad practice to have multiple views for same URL in MVC, based on different user roles? For example:
http://www.domain.com/ViewProductID/123 will show a “normal” product page for a regular user and it will show an “enhanced” (product stats, ability to edit title etc..) version to someone logged in as admin.
If it’s bad practice, why? If it’s ok, what’s the best way to implement it? 2 separate templates or 1 template scattered with if..else?
Thanks!
I think it’s fine to modify the view based on context; it happens all the time. Whether you do the if.. else or the multiple aspx files is really dependant on how much is different. A couple alternate options:
1) use Html.RenderAction to call against an AdminController actions to embed the stuff, the AdminController can return empty results if the user isn’t an admin
or, better:
2) use a different Master page based on the user’s role / status. This way, you can pull the logic for setting the master into an actionfilter ot he like, and do it one time but apply it wherever it makes sense. Just make sure that the alternate Master pages are compatible w/ the views in terms of the contentplaceholderId’s.