I'm a beginner in C # MVC 4 and I set up a website for learning purposes.
On the contact page of the site there is a form that automatically sends emails. When I squeeze it locally straight from Visual Studio 2013 (IIS Express) it sends the emails quietly and loads the view of "success".
All right until I upload to the Locaweb server. Now it gives a 404 error:
Server Error in '/ user / site' Application.
The resource can not be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Requested URL: / username / site / en / Contact / Sent /
Version Information: Microsoft .NET Framework Version: 4.0.30319; ASP.NET Version: 4.0.30319.34280
The big problem is that the views are all there. I ran the internet and they told me that I could call the view with the direct path, but it also did not work: (
In this case I do not understand if what he is not finding is Action
or View
return View()
.
Here is the action that is in my contact page controller:
[HttpPost]
public ActionResult Sent(Formulario formulario)
{
if (formulario.Validar())
{
try
{
var mensagem = formulario.Mensagem.Replace(Environment.NewLine, "<br/>");
var smtpUri = ConfigurationManager.AppSettings["smtpUri"];
var smtpPort = Convert.ToInt32(ConfigurationManager.AppSettings["smtpPort"]);
var emailTo = ConfigurationManager.AppSettings["emailTo"];
var client = new SmtpClient(smtpUri, smtpPort)
{
EnableSsl = false,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential("meuEmail", "minhaSenha")
};
var mail = new MailMessage("meuEmail, emailTo);
mail.IsBodyHtml = true;
mail.Subject = String.Format("Contato via site - Página: {0}", formulario.Pagina);
mail.Body = mensagem;
client.Send(mail);
return View("~/Views/Contact/Sent.cshtml");
}
catch (Exception e)
{
return View("~/Views/Contact/Error.cshtml");
}
}
return Json(new {success = false});
}
My RouteConfig.cs:
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute("i18n", "{language}/{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional, language = "pt-br" },
new { language = "en|pt|es|pt-br|en-us" }
);
routes.MapRoute("Default", "{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
In fact "/usuario/site"
is because the site is in the air inside a subfolder because I do not want it to be in the air with errors yet. It works smoothly on every page, except when I try to email the contact page.
Does anyone have any idea what it can be ?! Thank you !!