0
I am a beginner in C# MVC 4 and have set up a site for learning purposes.
On the contact page of the site there is a form that sends emails automatically. When I run it locally direct from Visual Studio 2013 (IIS Express) it sends the emails quietly and loads the view of "success".
All right until I go up to the Locaweb server. Now it gives a 404 error:
Server Error in '/user/site' Application.
The Resource cannot 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 is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Requested URL: /usuario/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 reviewed the internet and I was told that I could call the view with the direct way, but it also did not work :(
In this case I did not understand if what he is not thinking is the Action
or the View
of return View()
.
Follow the action 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 the "/usuario/site"
is because the site is on the air within a subfolder because I don’t want it to be on the air with errors yet. It is working smoothly on all pages, except when trying to send an email through the contact page.
Does anyone have any idea what it might be?! Thank you!!
You could put the routes you’re using here?
– PauloHDSousa
I updated the question with the route settings, Paulo. Thank you!
– Felipe Rugai
I solved my problem by adding a bar ("/") to the end of the call URL!
– Felipe Rugai