Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Alistair Jenkins 92 posts 315 karma points
    Nov 17, 2017 @ 16:23
    Alistair Jenkins
    0

    Adding controller to app_code dir crashes my site

    So, I'm trying to add a contact form following the instructions here:

    https://our.umbraco.org/documentation/Getting-Started/Code/Creating-Forms/

    and when it came to adding the controller it suggests putting it in the controllers folder. However looking at the directory tree I can find no controllers folder, so I Google where to find it and find a post saying that if you aren't using Visual Studio (I'm not) you won't have a controllers folder but you can put the file in App_Code. I copy the code from the guide above into a file called ContactController.cs in that directory and then return to the Umbraco backend and as soon as I try to do something I get a server error message and a little after that the screen of death. Removing the controller file and restarting the server brought everything back.

    I found this message in the error log:

    shutDownMessage=Change Notification for critical directories. AppCode dir change or directory rename HostingEnvironment initiated shutdown Change in D:\local\Temporary ASP.NET Files\root\11bb0ad1\f4398f03\hash\hash.web HostingEnvironment caused shutdown

    The site is hosted on Azure and I'm using Kudu to access the directories. Am I just not going to be able to achieve what I want using these instructions and if not, is there a better way? I'm not experienced with Umbraco so any help would be greatly appreciated.

    Cheers, Alistair

  • Steve Morgan 1345 posts 4452 karma points c-trib
    Nov 17, 2017 @ 16:31
    Steve Morgan
    0

    Unless I'm mistaken (and I often am) it then should start up again. What's probably happening is there is a syntax error in your controller.

    Are there any other expections / errors in the logs or anything shown on the site?

  • Alistair Jenkins 92 posts 315 karma points
    Nov 17, 2017 @ 16:38
    Alistair Jenkins
    0

    Thanks for the reply. Here's the code from the guide:

     using MyFirstForm.Models;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using Umbraco.Web.Mvc;
    
     namespace MyFirstForm.Controllers
     {
          public class ContactFormController : SurfaceController
     {
        [HttpPost]
        public ActionResult Submit(ContactFormViewModel model)
        {
            if (!ModelState.IsValid)
                return CurrentUmbracoPage();
    
            /// Work with form data here
    
            return RedirectToCurrentUmbracoPage();
        }
      }
    }
    

    The only bit I changed was to change MyFirstForm to ClearviewForm. Is there something wrong there?

  • Alistair Jenkins 92 posts 315 karma points
    Nov 17, 2017 @ 16:41
    Alistair Jenkins
    0

    Ah, after posting that I noticed the reference to "using MyFirstForm.Models;" which I think should be ClearviewForm.Models to fit in with what I've done elsewhere. Would that cause the crash? I'll try again with that change.

  • Alistair Jenkins 92 posts 315 karma points
    Nov 17, 2017 @ 16:47
    Alistair Jenkins
    0

    Nope. tried again with that change and site still crashes. Didn't have to restart server though - came back as soon as I'd removed the controller again.

  • Steve Morgan 1345 posts 4452 karma points c-trib
    Nov 17, 2017 @ 16:51
    Steve Morgan
    0

    Are there other errors near what you posted before?

  • Steve Morgan 1345 posts 4452 karma points c-trib
    Nov 17, 2017 @ 16:57
    Steve Morgan
    100

    Oh and are your models in ClearviewForm.Models is the AppCode folder too? Anything that isn't generated by Umbraco won't be compiled at runtime unless it's in there.

  • Alistair Jenkins 92 posts 315 karma points
    Nov 17, 2017 @ 16:57
    Alistair Jenkins
    0

    The only messages I see are all related to App_Code dir change. Then there's what looks like standard shutdown/startup messages, of the type:

     2017-11-17 16:46:58,104 [P13168/D6/T6] INFO  Umbraco.Core.PluginManager - Resolving umbraco.interfaces.IDiscoverable
     2017-11-17 16:46:58,104 [P13168/D6/T6] INFO  Umbraco.Core.PluginManager - Resolved umbraco.interfaces.IDiscoverable (took 0ms)
     2017-11-17 16:46:58,104 [P13168/D6/T6] INFO  Umbraco.Core.PluginManager - Resolving [Umbraco.Core.Persistence.Mappers.MapperForAttribute]Umbraco.Core.Persistence.Mappers.BaseMapper
     2017-11-17 16:46:58,165 [P13168/D6/T6] INFO  Umbraco.Core.PluginManager - Resolved [Umbraco.Core.Persistence.Mappers.MapperForAttribute]Umbraco.Core.Persistence.Mappers.BaseMapper (took 52ms)
    
  • Alistair Jenkins 92 posts 315 karma points
    Nov 17, 2017 @ 16:59
    Alistair Jenkins
    0

    Ah, no. The Models are in the Models folder, which is where the guide said to put it. I will try moving it from there to the App_Code folder and see if that sorts it.

  • Alistair Jenkins 92 posts 315 karma points
    Nov 18, 2017 @ 11:40
    Alistair Jenkins
    0

    That has solved the crashing issue. Thanks Steve. Now I have to work out what to put in the '///Work with form data here' section. I take it I should still use Razor here?

    Also, can I reference a field in the backend so a customer can set which email address to send the contact form contents to?

    Cheers, Alistair

Please Sign in or register to post replies

Write your reply to:

Draft