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.
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?
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.
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.
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.
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.
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?
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
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?
Thanks for the reply. Here's the code from the guide:
The only bit I changed was to change MyFirstForm to ClearviewForm. Is there something wrong there?
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.
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.
Are there other errors near what you posted before?
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.
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:
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.
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
is working on a reply...