Trying to built menu from MenuHelperModel
causes MvcSiteMap to construct all my controllers. That could be a big performance hit.
Is this only way to go when I rely on [Authorize]
to set up security for controllers?
First of all, constructors should be simple. If creating your controllers on each request is slowing your application down, it is a sign that your constructors are doing too much work. The MVC framework creates one instance per request, anyway, so this is likely slowing down more than just MvcSiteMapProvider
.
That said, there is another option. You can use the roles attribute/Roles property to set the same roles as you have in AuthorizeAttribute. The downsides of doing this are:
You might be able to work around the first limitation by making a dynamic node provider that scans your application using Reflection and sets up the roles from AuthorizeAttribute as the roles of the corresponding node. This code is only run once per cache timeout, so having some Reflection at that point probably won't cause a performance problem.