开发者

New to asp.net. Need help debugging this email form

开发者 https://www.devze.com 2022-12-24 07:34 出处:网络
First of all, I am a php developer and most o开发者_如何学Cf .net is alien to me which is why I am posting here!

First of all, I am a php developer and most o开发者_如何学Cf .net is alien to me which is why I am posting here!

I just migrated over a site from one set of webhosting to another. The whole site is written in .net. None of the site is database driven so most of it works, except for the contact form. The output on the site simple states there was an error with "There has been an error - please try to submit the contact form again, if you continue to experience problems, please notify our webmaster." This is just a simple message it pops out of it gets to the "catch" part of the email function.

I went into web.config and changed the parameters:

    <emailaddresses>
        <add name="System" value="roeland@hoyespharmacy.com"/>
        <add name="Contact" value="roeland@bythepixel.com"/>
        <add name="Info" value="roeland@bythepixel.com"/>
    </emailaddresses>
    <general>
        <add name="WebSiteDomain" value="hoyespharmacy.com"/>
    </general>

Then the .cs file for contact contains the mail function EmailFormData():

private void EmailFormData()
{
    try
    {
        StringBuilder body = new StringBuilder();
        body.Append("Name" + ": " + txtName.Text + "\n\r");
        body.Append("Phone" + ": " + txtPhone.Text + "\n\r");
        body.Append("Email" + ": " + txtEmail.Text + "\n\r");
        body.Append("Fax" + ": " + txtEmail.Text + "\n\r");
        body.Append("Subject" + ": " + ddlSubject.SelectedValue + "\n\r");
        body.Append("Message" + ": " + txtMessage.Text);

        MailMessage mail = new MailMessage();
        mail.IsBodyHtml = false;
        mail.To.Add(new MailAddress(Settings.GetEmailAddress("System")));
        mail.Subject = "Contact Us Form Submission";
        mail.From = new MailAddress(Settings.GetEmailAddress("System"), Settings.WebSiteDomain);
        mail.Body = body.ToString();

        SmtpClient smtpcl = new SmtpClient();

        smtpcl.Send(mail);
    }
    catch
    {
        Utilities.RedirectPermanently(Request.Url.AbsolutePath + "?messageSent=false");
    }
}

How do I see what the actual error is. I figure I can do something with the "catch" part of the function.. Any pointers?

Thanks!


Change the catch to

catch(Exception ex)
{
   throw;
}

The ex variable will hold your exception information, so you can put a breakpoint there. It'd be easier to step through it, but you can just throw the error as well.


Comment out Utilities.RedirectPermanently(Request.Url.AbsolutePath + "?messageSent=false"); and replace it with throw;


What development environment are you using?

It's probably best to use Visual Studio (Express if you don't have the full version), and debug this code, hitting F11 to step through each statement until it breaks. Then you should have access to more information.


I would suggest logging in the long term (such as log4net). But for the sake of speed try changing your catch statement to look like:

catch(Exception e)

and then use the debugger in VS to explore the actual exception.


Place a breakpoint on the first line of the EmailFormData method and run the application in debug mode. You can then step through the code line by line.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号