Orchard routes to custom module not working

Topics: Troubleshooting, Writing modules
Nov 1, 2013 at 10:29 PM
I have a simple module. It has 2 form handlers. At one point it was working, I'm not really sure what changed that caused it to stop working but basically here is what's happening:

I cannot get my custom module working. Using the razor form helpers yields an empty action and using url.action also returns empty. I've noticed if I remove the "area" route key then it does produce a result (although be it incorrect). It produces something like http://www....com/Contents/MyController/MyAction/ which produces a 404. However, if I add the "area" value back it returns empty.

Here is my controller:
namespace CodeSmart.Module.ComingSoon.Controllers
    public class HomeController : Controller
        #region Actions
        public ActionResult Index()
            // -- Does Nothing
            return View();
My routes file:
public IEnumerable<RouteDescriptor> GetRoutes() {
            return new[] {
                new RouteDescriptor {
                    Priority = 0,
                    Route = new Route(
                        new RouteValueDictionary {
                            {"area", "Module.ComingSoon"},
                            {"controller", "Home"},
                            {"action", "Index"},
                            {"id", UrlParameter.Optional}
                        new RouteValueDictionary(),
                        new RouteValueDictionary {
                            {"area", "Module.ComingSoon"}
                        new MvcRouteHandler())
My Module.txt:
name: Coming Soon
path: Module.ComingSoon
antiforgery: enabled
author: The Orchard Team
website: http://orchardproject.net
version: 0.5.0
orchardversion: 0.5.0
category: CodeSmart Studios
description: Coming soon module encompassing newsletter and contact us functionality.
        Description: Core features of coming soon module.  Includes newsletter and contact us.
        Category: CodeSmart Studios
And finally how I'm trying to use it:
@using (Html.BeginForm("Subscribe", "Home", new {area="Module.ComingSoon"}, FormMethod.Post, new {@id = "form-subscribe", @name = "form-subscribe"}))
As I said at one point it was working. I dont know what caused it to stop working, I was working on getting deployment working on Azure. I hadn't touched anything in the custom module project during that.
Nov 1, 2013 at 10:30 PM
As a side note, although the namespace does not match the module name, the project file is physically called "Module.ComingSoon" and the folder underneath the Orchard installation is also named "Module.ComingSoon".
Nov 1, 2013 at 10:52 PM
Does your module compile? If you can test on local development with Visual Studio, build the solution and restart IIS if no errors are generated.

Nov 1, 2013 at 10:55 PM
Yes, the module compiles. Restarting IIS does not effect it. I noticed the problem existed after I got the azure deployment set up and successfully deployed. I realized the forms weren't working on production after deploying to Azure so I then checked locally and locally observed the problem too so I'm almost at a loss.
Nov 1, 2013 at 11:18 PM
Does anything in the module work?
Nov 1, 2013 at 11:20 PM
Ha, I suppose what anything means. There's currently only 2 form handlers. Neither of the controllers are being hit, but the module compiles, shows up in the Modules admin area and is enabled.
Nov 2, 2013 at 12:38 AM
That doesn't mean anything other than that the manifest is there and valid. If you put a breakpoint in GetRoutes, does that get hit?
Nov 2, 2013 at 1:01 AM
Alright I finally solved it. After trying basically everything I could think of short of blowing the entire module away and starting from a clean Orchard module scaffolding I, for whatever reason, started comparing the config files in my Config folder to the ones inside a clean orchard source. I remembered I had changed these in all sorts of ways trying to get it to play nice with Azure, and there it was, the "HostingComponents.config" file had major discrepencies from the clean Orchard.Web config file.

I just copied over and overwrote every config file in the folder with the clean source, refreshed, and it started working again locally. Published to azure crossing my fingers and it worked!

Now if I can only get these configuration transformations working for the Host, HostComponents, and log4net config files so I don't have to comment out / uncomment the azure settings while developing locally or publishing to staging or production.

Thanks for the help.
Nov 2, 2013 at 1:19 AM
Alright nevermind - it is still not working. Everything I described above was correct, however after publishing to azure it did not fix it. It now works locally, even running on the azure emulators. The Url.Action's and Html.BeginForm's are working as expected. Publishing to azure, however, did not fix the problem. The action and forms are still empty as if the GetRoutes isn't being picked up.

I've stepped through it locally and it is being found then. I've restarted IIS, the app pool, and even the server. Nothing.
Nov 2, 2013 at 1:41 AM
Wow - I don't even know where to start, but I found the solution.

It's basically due to the culmination of hours spent on getting it to deploy and work on Azure. @BertrandLeRoy you led me on the right path, you got me thinking maybe Orchard was cached or not dynamically picking up changes to the module. I read up on how Orchard loads and reads the filesystem, and after EVERYTHING checked out, I had absolutely no clue what to do.

I had to see what was going on in the server so I RDC'd in to inspect the website's folder. I went into my custom modules folder and ah-ha! All the .cs files were missing. What had happened is this - when I built the solution I built out the scaffolding for my module using orchard's command line, then added the existing project to my solution. This was working great for dev, but the problem with deploying to Azure is that in mult-instance environments you have to include all your modules and themes in the deployment package. This forced me to Include my theme and custom module files within my web project so that when deployed the files would go up with it. Problem was all the .cs files were set to "compile". So when my web project would compile, the .cs files would compile right along with it, hence never reaching the server and never loading GetRoutes! Switching these to "content" and 1 FINAL deployment later, we're back in business!

I hope this helps someone else, this was a hard one to track down!