部署项目后调用webmethod的问题

时间:2015-03-05 22:04:29

标签: c# jquery ajax hosting web-deployment

这是我的设置。

我有一个表单,用户可以在其中留下电子邮件以获取通知。

    <form id="contactForm" class="form-inline" role="form">
        <div class="input-group">
            <label class="sr-only" for="inputEmail">Email address</label>
            <input type="email" class="form-control" id="inputEmail" placeholder="Enter email" />
<span class="input-group-btn"><button id="sendEmail" type="submit" class="btn btn-info">Get notified!</button></span>
        </div>
        <div id="sendmessage"></div>
    </form>

在提交表单时,进行以下Ajax调用:

$(function () {
            $("[id*=sendEmail]").click(function () {
                var obj = {};
                obj.from = $.trim($("[id*=inputEmail]").val());
                $.ajax({
                    type: "POST",
                    url: "Default.aspx/SendParameters",
                    data: JSON.stringify(obj),
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: OnSuccess,
                    failure: function (r) {
                        alert(r.d);
                    }

                });
                return false;
            });
        });

反过来调用以下webmethod

[WebMethod]
        public static string SendParameters(string from)
        {
            if (string.IsNullOrEmpty(from))
            {
                return string.Format("Please complete the form.");
            }
            else
            {
                try
                {
                    SmtpClient client = new SmtpClient();
                    client.Port = 80;


                    client.Host = "smtpout.europe.secureserver.net";

                    client.EnableSsl = false;
                    client.Timeout = 10000;
                    client.DeliveryMethod = SmtpDeliveryMethod.Network;
                    client.UseDefaultCredentials = false;
                    client.Credentials = new System.Net.NetworkCredential("my@email.com", "myPassword");
                    MailMessage mm = new MailMessage(from, "my@email.com", "Notify website launch", "Please let me know when it's ready!");
                    mm.BodyEncoding = System.Text.UTF8Encoding.UTF8;
                    mm.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
                    client.Send(mm);
                    return string.Format("Thank you!<br/>I'll be in touch soon.");
                }
                catch (Exception)
                {

                    return string.Format("Oops, your message could not be sent.<br/>Please retry.");
                }
            }
        }

在本地,这就像发条一样,但在将我的项目部署到GoDaddy共享服务器之后,会抛出最严重的错误:

  

POST http://simoneduca.com/Default.aspx/SendParameters 500(内部服务器错误)

有没有人经历过类似的事情?

我一直在抨击我的头3个小时,所以任何建议都会非常受欢迎。

(我喜欢SO建议bash作为此问题的标签,LOL)

0 个答案:

没有答案