Adding Areas to an MVC application - any gotchas?
Asked Answered
C

1

7

I have an ASP.net MVC application that has been in Production for a while. I would like to add a new Admin section to the application which I wanted to do by creating a new Area. I'm just curious what sorts of things I might need to be aware of when adding this new area.

Specifically:

  1. Is there any existing functionality that is likely to break by adding the new Area?
  2. What is the best way to make an Area restricted to a certain group? Base controller class?
  3. Any other things (common mistakes, etc.) that I need to be aware of that adding a new Area will affect?
Cheng answered 26/3, 2012 at 19:8 Comment(3)
I'd use an Area for this. I'd also add unit tests for all existing routes to make sure they don't break when you add your new area and its routes.Kingly
Are you already using Areas for other sections?Duodenary
@Duodenary Nope, this will be the first one.Cheng
T
3

One thing to be careful of is naming collisions - if you have 2 controllers with the same name but in different areas you need to add namespaces, as described here: http://haacked.com/archive/2010/01/12/ambiguous-controller-names.aspx

To restrict the admin area to a certain group, you could use the Authorize attribute with Roles on the Admin controller(s), as desribed here: ASP.NET MVC 3 - How to restrict areas in an efficient way?

Thistle answered 26/3, 2012 at 21:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.