C # MVC 4-action gives Error 404 [closed]

closed. this question is out of scope and is not currently accepting answers.

want to improve this question? Update the question so it's on-topic for Stack Overflow.

Closed 3 years ago .

improve this question

I am a beginner in c # MVC 4 and have set up a website for learning purposes.

On the Contact page of the site there is a form that sends emails automatically. When I squeegee it locally direct from Visual Studio 2013 (IIS Express) it sends the emails quietly and loads the "success"view.

All right until I go up to the Locaweb server. Now it gives an error 404:

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 / pt-br / Contact / Sent /

Information Version: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 turned over the internet and was told that I could call the view with the direct path, but it didn't work either: (

In this case I did not understand if what he did not you're finding is Action or View of return View().

Follows 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 }
                );
        }
    }

Actually "/usuario/site" is because the site is up in a subfolder because I don't want it to be up in the air with errors yet. It's working quietly on every page, except when I try to send an email through the Contact page.

Does anyone have any idea what it might be?! Thank you!!

Author: Bacco, 2015-12-14

1 answers

From what I saw, this view will be rendered only if the verb used is the POST. try adding the [HttpGet] attribute and post again to see if it works.

Another thing caught my eye in your url: / usuario / site / en-br/Contact / Sent /

Is this correct?

We usually use something more simplified like " http://www.site.com.br/NomeDoController/NomeDaAction "

In your case I think it would be / Contact (Controller) e A Action / Sent

 1
Author: Thiago Custodio, 2015-12-14 17:39:45