Based on a couple of guides I found I have created a model and controller in my app_code directory, but they crash my site. I've been looking at them for a while now, but I don't know enough to work out what's going wrong.
Model: ContactFormViewModel.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace ClearviewForm.Models
{
public class ContactFormViewModel {
public string Name { get; set; }
public string Email { get; set; }
public string Message { get; set; }
}
}
Controller: ContactFormController.cs
using ClearviewForm.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Umbraco.Web.Mvc;
namespace ClearviewForm.Controllers
{
public class ContactFormController : SurfaceController
{
/// <summary>
/// Renders the Contact Form
/// @Html.Action("RenderContactForm","ContactFormSurface");
/// </summary>
/// <returns></returns>
public ActionResult RenderContactForm()
{
//Return a partial view ContactForm.cshtml in /views/ContactForm/ContactForm.cshtml
//With an empty/new ContactFormViewModel
return PartialView("ContactForm", new ContactFormViewModel());
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult HandleContactForm(ContactFormViewModel model)
{
//Check if the data posted is valid (All required's & email set in email field)
if (!ModelState.IsValid)
{
//Not valid - so lets return the user back to the view with the data they entered still prepopulated
return CurrentUmbracoPage();
}
//Generate an email message object to send
MailMessage email = new MailMessage(model.Email, "[email protected]");
email.Subject = "Contact Form Request";
email.Body = model.Message;
try
{
//Connect to SMTP credentials set in web.config
SmtpClient smtp = new SmtpClient();
//Try & send the email with the SMTP settings
smtp.Send(email);
}
catch (Exception ex)
{
//Throw an exception if there is a problem sending the email
throw ex;
}
//Update success flag (in a TempData key)
TempData["IsSuccessful"] = true;
//All done - lets redirect to the current page & show our thanks/success message
return RedirectToCurrentUmbracoPage();
}
}
}
I added using System.Net.Mail; in to my controller and tried again, but still get the ysod.
The error that appears at the bottom of the log file directly after doing that is as follows:
_shutDownMessage=Change Notification for critical directories.
App_Code dir change or directory rename
HostingEnvironment initiated shutdown
Change Notification for critical directories.
App_Code dir change or directory rename
Change Notification for critical directories.
App_Code dir change or directory rename
HostingEnvironment caused shutdown
_shutDownStack= at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)
at System.Environment.get_StackTrace()
at System.Web.Hosting.HostingEnvironment.InitiateShutdownInternal()
at System.Web.Hosting.HostingEnvironment.InitiateShutdownWithoutDemand()
at System.Web.HttpRuntime.ShutdownAppDomain(String stackTrace)
at System.Web.HttpRuntime.OnCriticalDirectoryChange(Object sender, FileChangeEvent e)
at System.Web.FileChangesMonitor.OnCriticaldirChange(Object sender, FileChangeEvent e)
at System.Web.DirectoryMonitor.FireNotifications()
at System.Web.Util.WorkItem.CallCallbackWithAssert(WorkItemCallback callback)
at System.Web.Util.WorkItem.OnQueueUserWorkItemCompletion(Object state)
at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
Syntax error in controller?
Hi,
Based on a couple of guides I found I have created a model and controller in my app_code directory, but they crash my site. I've been looking at them for a while now, but I don't know enough to work out what's going wrong.
Model: ContactFormViewModel.cs
Controller: ContactFormController.cs
Any help gratefully appreciated,
Cheers, Alistair
Hey Alistair,
Is there any error in the logs?
A guess - are you missing
using System.Net.Mail
in your controller?Hi Matt,
I added
using System.Net.Mail;
in to my controller and tried again, but still get the ysod.The error that appears at the bottom of the log file directly after doing that is as follows:
is working on a reply...