an email is causing errors

M J 636 Reputation points
2023-01-11T21:31:01.5866667+00:00

One of our business partners provided an email for her client to send out to prospective employees that missed a space between the URL and the instructions, and now is throwing errors in my MVC application which then sends me notification of the error. The email says

Click the link https://beta.commonwealthhotelsassessments.com/or cut/paste (-> https://beta.commonwealthhotelsassessments.com/or%2520cut/paste) this website address into the address bar, and then choose Click Here for New User Registration. Fill in the required information to Register to Take an Assessment. Then click the Register button.”

basically the error messages I am getting say

The controller for path '/or cut/paste' was not found or does not implement IController.

I have asked our business partner to correct the email template and send to Commonwealth Hotels (her client) but they are still sending the bad emails out. Is there something I can do on the site to redirect the user when this occurs so that they are taken right to the home page?

ASP.NET MVC
ASP.NET MVC
A Microsoft web application framework that implements the model-view-controller (MVC) design pattern.
617 questions
{count} votes

3 answers

Sort by: Most helpful
  1. M J 636 Reputation points
    2023-01-13T21:07:34.5+00:00

    my error reporting model looks like this

    
    using System;
    using System.Diagnostics;
    using System.Web;
    using MailKit.Net.Smtp;
    using MimeKit;
    
    namespace Commonwealth.Models
    {
        public class Errors
        {
            public static void ErrorOccured(Exception ex)
            {
                var st = new StackTrace(ex, true);
                // Get the top stack frame
                var frame = st.GetFrame(0);
                // Get the line number from the stack frame
                var line = frame.GetFileLineNumber();
                string page = frame.GetFileName();
                var col = frame.GetFileColumnNumber();
    
                string domain = HttpContext.Current.Request.Url.Host;
                string MailBody = ex.Message.ToString() + "\r\n
                string MessageToSend = ex.StackTrace.ToString();
                string MailSender = "website email";
                string MailRecipient = "my email";
                string MailSubject = "Error on " + domain;
                MimeMessage msg = new MimeMessage();
    
                msg.From.Add(new MailboxAddress("", MailSender));
                msg.To.Add(new MailboxAddress("",MailRecipient));
                msg.Subject = MailSubject;
                msg.Body = new TextPart(MimeKit.Text.TextFormat.Html) { Text = MailBody + "\r\n
                using (var smtp = new SmtpClient())
                {
                    smtp.Connect("emailserver", 587, false);
                    smtp.Authenticate("emailuser", "password");
                    smtp.Send(msg);
                    smtp.Disconnect(true);
                }
            }
        }
    }
    

    and then the controller has this

    
    public ActionResult About()
            {
                try
                {
                    return View();
                }
                catch (Exception ex)
                {
                    Errors.ErrorOccured(ex);
                }
                return RedirectToAction("Index", "Error", null);
            }
    

  2. Bruce (SqlWork.com) 28,281 Reputation points
    2023-01-15T18:28:23.3966667+00:00

    You can use iis url rewrite to fix the url. Or make it a valid route, typically with attribute routing.

    [https://www.iis.net/downloads/microsoft/url-rewrite


  3. QiYou-MSFT 851 Reputation points Microsoft Employee
    2023-01-25T09:40:06.61+00:00

    Hi @M J

    Please try the overloading method

    public ActionResult About()
            {
                
                    return View();
                
            }
    [HttpPost]
    public ActionResult About()
            {
                try
                {
                    return View();
                }
                catch (Exception ex)
                {
                    Errors.ErrorOccured(ex);
                    return RedirectToAction("Index", "Error", null);
                }
                
            }
    

    Best Regards

    Qi You


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.