I would like to change navigation bar in my application depending on who is loged in. I don't want customer to see links available to admin for example. From information that I've found so far I think I will have to create couple of versions of layout and use wright one with appropriate view. If I'm wrong what is the best way to do it?
-
Can you provide some details regarding your layout? What is the difference in terms of links changes between normal user and an administrator?Alexei - check Codidact– Alexei - check Codidact2016-04-30 16:44:25 +00:00Commented Apr 30, 2016 at 16:44
-
@ Alexei I just want to make website look as easy to read and clear as possible, so cutomer does not need to see links for admin for which will have no access anyway. After log in customer enter his part of app and see links that will use and have access to. The same with admin.Zet– Zet2016-04-30 16:54:18 +00:00Commented Apr 30, 2016 at 16:54
1 Answer
In most Web applications administration area is quite different from "operational" area (that dedicated to normal users). Providing more details might be useful, but I recommend to use areas, a feature of MVC:
they allow to have a clear separation by semantics of content. In your case this means administration vs. other parts of the application
each area can define a default layout (or other layout pages) to be used in that particular area
Using the same layout between administrative and other part of your application might force into ugly code like the following:
if (@Model.IsAdmin)
{
// show admin link 1 here
}
// normal user or public content here
if (@Model.IsAdmin)
{
// other code accessible for admin only
}
So, shortly put, I advice for separation.