[英]The Code Works Fine When Debugging, But it Doesn't work when it runs without Debugging
[英]Code runs fine on localhost but doesn't execute on gatorhost
我在VWD上寫了一個小型網站。 我正在使用VWD的localhost功能在我的家用計算機上運行它。 它運行完美。
現在是背景故事。 我有一個帶有gatorhost的Linux服務器。 我讓他們將域和服務器類型切換到Windows,因為我決定學習asp.net(c#)。 我花了幾個小時打電話給他們。 當您搜索我的域以及所有混亂的電子郵件功能和ftp功能時,無法連接的問題使他們花了幾個小時才能在多個呼叫和票證中找出來。
因此,現在我想我可以正常工作了,我通過VWD將網站加載到服務器(www.contentiousweb.com)上,就表單驗證和鏈接而言,我所有的前端代碼都可以正常工作。
當我點擊執行我的C#代碼的提交按鈕時,什么也沒有發生。 沒事 當表格填寫錯誤時,驗證有效。 我沒有任何錯誤。 我喜歡不知道從哪里開始。 是我的代碼在服務器上嗎,我可以在多大程度上依靠VWD,因為我不能依靠自己的笑聲。
Webconfig文件。 (我換了我的密碼和電子郵件)
<system.net>
<mailSettings>
<smtp deliveryMethod="Network" from="Ralph <********@hotmail.com>">
<network enableSsl="true" host="smtp.live.com" userName="*************@hotmail.com" password="***********" port="587" />
</smtp>
</mailSettings>
</system.net>
波紋管是按鈕。
protected void Button1_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
string fileName = Server.MapPath("_TextFiles/ContactForm.txt");
string mailBody = File.ReadAllText(fileName);
mailBody = mailBody.Replace("##Name##", nameBox.Text);
mailBody = mailBody.Replace("##Email##", emailBox.Text);
mailBody = mailBody.Replace("##Subject##", subBox.Text);
mailBody = mailBody.Replace("##Message##", MsgField.Text);
MailMessage myMessage = new MailMessage();
myMessage.Subject = "Response from Contact Page";
myMessage.Body = mailBody;
myMessage.From = new MailAddress("******", "Contact");
myMessage.To.Add(new MailAddress("******", " Server"));
SmtpClient mySmtpClient = new SmtpClient();
mySmtpClient.Send(myMessage);
Message.Visible = true;
ContactTable.Visible = false;
System.Threading.Thread.Sleep(5000);
}
}
}
任何幫助將不勝感激。 我是新手,正在學習,但是由於我的經驗和與hostgator的關系,我認為這是一種終結,因為其他所有事情都發生了。 我無能為力。
請讓我知道是否還有我可以提供的信息。 感謝您的任何幫助
在我自己的故障排除中,我剛剛使用mozila開發工具發現了此錯誤。
[18:03:28.399] Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server. The status code returned from the server was: 500 @ http://contentiousweb.com/ScriptResource.axd?d=EJBSV2JIVC3wCtbtVqDWEZfeOsqUeA-l1kZnjjZKvx15e0cjnzPdj4H78hvszmtfrIhAM96VdUstdDjn1xGAbsydMzIjEQeNWDOz2tihnjEjxDW5esVemHLoHR01oIyUBoZTNPd7atx4-EPBnuVlWYbQIeLdoH_eBXy1j9kav6ac2ptv4Cl8sraaDBGXntVH0&t=ffffffff940d030f:1507
感謝您的幫助,我仍在尋找自己的答案。
我知道了 與gatorhost在電話上交談了四個小時后,我們確定他們向我提供的smtp信息將無法正常工作。 他們讓我將主機更改為
<system.net>
<mailSettings>
<smtp deliveryMethod="Network">
<network host="localhost" userName="*************@hotmail.com" password="***********" port="25" />
</smtp>
</mailSettings>
</system.net>
現在一切正常,沒有錯誤。 謝謝所有提供創意的人。
在您的代碼中看不到分配端口號或憑據的信息?
此代碼應該有效
// SMTP options
string Host = "smtp.mail.emea.microsoftonline.com";
Int16 Port = 587;
bool SSL = true;
string Username = "myname@mydomain.com";
string Password = "mypassword";
// Mail options
string To = "reciever@recieverdomain.com";
string From = "myname@mydomain.com";
string Subject = "This is a test";
string Body = "It works!";
MailMessage mm = new MailMessage(From, To, Subject, Body);
SmtpClient sc = new SmtpClient(Host, Port);
NetworkCredential netCred = new NetworkCredential(Username, Password);
sc.EnableSsl = SSL;
sc.UseDefaultCredentials = false;
sc.Credentials = netCred;
try
{
Console.WriteLine("Sending e-mail message...");
sc.Send(mm);
}
catch (Exception ex)
{
Console.WriteLine("Error: {0}", ex.ToString());
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.