Module Admin Page not showing?

Topics: Writing modules
Jul 30, 2012 at 11:10 AM
Edited Jul 30, 2012 at 11:10 AM

I'm playing around with my first module that needs admin pages, and can't seem to get the AdminController for it to behave.

I have:

  • Controllers/AdminController.cs
        public class AdminController : Controller
            public AdminController(IContentManager contentManager)
                _contentManager = contentManager;
            private IContentManager _contentManager;
            public ActionResult Index()
                // Create the viewmodel
                ModViewModel model = new ModViewModel();
                return View(model);
  • Views/Admin/Index.cshtml
    (Just a "Hello world" page for now) 

  •  AdminMenu.cs
        public class AdminMenu : INavigationProvider
            public string MenuName
                get { return "admin"; }
            public AdminMenu()
                T = NullLocalizer.Instance;
            private Localizer T { get; set; }
            public void GetNavigation(NavigationBuilder builder)
                    .Add(T("Testing"), "2", menu => menu.Action("Index", "Admin", new { area = "Mod" })
                        .Add(T("Function 1"), "0", item => item.Action("Index", "Admin", new { area = "Mod" }).Permission(StandardPermissions.AccessAdminPanel))

  • Routes.cs
        public class Routes : IRouteProvider
            public void GetRoutes(ICollection<RouteDescriptor> routes)
                foreach (var routeDescriptor in GetRoutes())
            public IEnumerable<RouteDescriptor> GetRoutes()
                return new[] 
                    new RouteDescriptor 
                        Priority                   =  11,
                        Route = new Route(
                            new RouteValueDictionary {
                                {"area", "Mod"},
                                {"controller", "Admin"},
                                {"action", "Index"}
                            new RouteValueDictionary(),
                            new RouteValueDictionary {
                                {"area", "Mod"}
                            new MvcRouteHandler())

So far so good. But, when you try and hit http://orchardlocal/admin/mod I get a 404 page (The resource cannot be found).  I have tried enabling the debug logging, but nothing relevant appears here. Putting a breakpoint in the controller seems to indicate that the controller is not being "found" and created by Orchard - but for the life of me I can't work out why.

Any pointers?


Jul 30, 2012 at 12:48 PM

Does your action get hit when you navigate to it directly? E.g. if your module project is called Mod, then try navigating to: http://orchardlocal/Mod/Admin/Index

If that works, then it's the routing that doesn't work for some reason. You may simply have to reset your application though (save web.config). This worked for me a few days ago when I was having a similar issue.

Jul 30, 2012 at 12:53 PM
Edited Jul 30, 2012 at 12:55 PM

Hi sfmskywalker,

Thanks for the reply - unfortunatly if I try and hit the module directly (either with http://orchardlocal/mod/admin/index or http://orchardlocal/admin/mod/index) I get the Orchard 404 page (Not Found) - i.e. no error page like what I get when hitting http://orchardlocal/admin/mod

I'm guessing because the routing only explicitly handles the latter case, and not the former (with actions).


Jul 30, 2012 at 1:10 PM

Follow up, I've just used Route Debugger and confirmed that my Admin/Mod route is being used for http://orchardlocal/admin/mod - but for some reason, I still end up with the 404? Perhaps Orchard is unable to find the controller or the view for some reason?

Jul 30, 2012 at 2:50 PM

Hmm.. and you're sure that the Index view is there in the Views/Admin folder?

Jul 30, 2012 at 2:51 PM
sfmskywalker wrote:

Hmm.. and you're sure that the Index view is there in the Views/Admin folder?

Sorry, you mentioned that, I overlooked it.

Jul 30, 2012 at 2:55 PM

I just built a module with exactly your code, there is nothing wrong with it as far as I can tell.
Did you check that the module is enabled (from the Modules section)?

Jul 30, 2012 at 2:57 PM

Yup, its enabled.

I'm going to have a shot at building a new module, with nothing but the basics (hello world on everything), just to see if I can reproduce this problem - if I can, I'll post it on here when done :)

It's got me completely stumped!

Jul 30, 2012 at 2:58 PM

http://orchardlocal/admin/mod seems a little bit out of place. Did you setup a host name "orchardlocal"? Or did you mean: http://localhost:3020/orchardlocal/admin/mod?

Jul 30, 2012 at 3:08 PM

orchardlocal is setup as a local hostname (to make life easier).

Jul 30, 2012 at 3:18 PM

I've created a clean, very very very basic module - and put the code I'm using in for the admin bits. It has the same issue.

Any chance you can take a look and see if I'm being a fool?

I'm using Orchard 1.5.1

Jul 30, 2012 at 3:39 PM

Just tested it, works like a charm. Could you try changing Orchard.Web to using the built-in web server Cassini or IIS Express? Or even better: start a clean install of Orchard, and test your module from there, just to see that the module does work. Perhaps there's something wrong with your IIS config or web.config of your Orchard install.

Jul 31, 2012 at 9:22 AM

Really odd - tried it on a different machine (same project etc) and it appears fine.

So. I wiped the project folder out on my machine, cleared Temp ASP.NET files, and refetched the project from source control. And hit F5.

Same problem.

Tried both Cassini and IIS Express 7.5 - all the same

Jul 31, 2012 at 10:31 AM

That's really strange, since other modules like Blogs do work fine on your machine?

Jul 31, 2012 at 10:38 AM

Yup, other modules work as expected. It's got to be something cached somewhere, but I havent a clue where. 

Tried uninstalling / reininstalling IIS Express, no change.

I'm due to format the machine, but its a curiosity thats annoying me!

Aug 22, 2012 at 2:47 AM

I had a similar situation getting error 404 for controllers/views that existed. I narrowed it down to the fact that the files were added outside Visual Studio (i.e. Windows Explorer or Web Matrix) and the module.csproj did not have them included in the files to be compiled.

Try opening csproj file in visual studio, and click the Show All File in the Solution Explorer pane. Locate ALL files (controller, views, models, view models, admin.cs, etc.), right click and click Include In Project. Save and close VS -- DO NOT Build the project.

Nov 30, 2012 at 2:39 PM

After spending 4 days to understand this issue on a module of mine I got the is for some reason view fails load orchard silently excludes it.

I narrowed down replacing my view with a very simple one containing only: 

@model dynamic
Hello world

then it loaded and worked. After that I have replaced content with my previous view and got the error (please note, do not swpa files, replace content... this does not dynamically compiles the view again... hopefully)

At that point my view loaded with an error.

My bet is that at some point deep in orchard code there is a code that tries to load the view and silently does a 404 if any error occours and not just if the view is not there.

I thing this is a BUG IMHO because nothing is logged and one has no clue that view throws an error, the 404 is just misleading....

ps: my orchard is 1.5

best regards, wonderful product anyway, I love it! 

Nov 30, 2012 at 4:05 PM

If you can provide repro steps, please file a bug.