Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I am trying to create a small CMS with ASP.NET MVC3, but I got confused in designing the administrator section.

I decided to create two areas, one for users and another for admin. In my CMS I have a Post and a News object, and I want to put create/edit/delete functions in the admin area and other function that related to users in the user area to achieve functionality in my CMS. For example I have two NewsController, one in the admin area (include create/edit/delete functions) and another in the user area (include preview(id) function).

Is this design good? How can I improve it?

share|improve this question

migrated from stackoverflow.com Jul 3 '11 at 23:03

This question came from our site for professional and enthusiast programmers.

2 Answers 2

I think that's a good use for areas and have done so myself. Just be sure to properly secure the request to the administrator role and that's easy with that design as you can do it on the each controller class with attributes or a controller base class that you use for all of the area controllers as discussed in this answer.

share|improve this answer
    
in my cms, for example i have tow newscontroller , one in admin area (include create/edit/delete function ) and another in user area ( include preview(id) function ) , is this design good ? –  Mojtaba Jul 3 '11 at 20:46
    
I don't see anything wrong with that as long as you aren't copying functionality between the two controllers. If you do need to share a common function, for example if the user has an edit feature you can always share code in partial views in the root area of the site, and extract common data access into services so that the controllers remain skinny and share common code. –  Turnkey Jul 4 '11 at 0:15

An alternative design to areas would be to design your application using RESTful conventions. That is to say start by identifying resources: Post, News, ... and design controllers for them PostsController, NewsController, ... which will contain the standard RESTful actions. Then decorate those actions with [Authorize] attribute in order to define in roles for users to access them.

share|improve this answer
    
your alternative is good but i want to encapsulate administrative functions in one place –  Mojtaba Jul 3 '11 at 15:47
    
@Mojtaba, areas are also a good way to implement this. –  Darin Dimitrov Jul 3 '11 at 15:51
    
That's exactly what Areas are supposed to be used for. –  PieterG Jul 3 '11 at 15:56
    
in my cms, for example i have tow newscontroller , one in admin area (include create/edit/delete function ) and another in user area ( include preview(id) function ) , is this design good ? –  Mojtaba Jul 3 '11 at 20:45
    
@Mojtaba, your question is a little vague, you haven't provided enough details about your scenario and it is difficult to give an objective answer. The approach which uses areas might also work. I have provided an alternative design. Here's what I would do: try both approaches and see which one works better for my scenario. –  Darin Dimitrov Jul 3 '11 at 21:31

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.