我有一種發(fā)送電子郵件的方法,它使用SmtpClient. 在此方法中,我有以下內(nèi)容await smtpClient.SendMailAsync (mail);。調(diào)用是從我的控制器發(fā)出的,具體取決于具體情況: [HttpPost] [AllowAnonymous] [ValidateJsonAntiForgeryToken] public async Task<ActionResult> RegisterParticipant(RegisterIndexBaseVm attendee) { if (attendee == null) return new HttpStatusCodeResult(HttpStatusCode.BadRequest); if (ModelState.IsValid) { attendee.EventId = Int32.Parse(Session["id"].ToString()); using (var client = new HttpClient()) { client.BaseAddress = new Uri(BaseUrl); client.DefaultRequestHeaders.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage Res = await client.PostAsync("Register/RegisterAttendee", new StringContent(JsonConvert.SerializeObject(Mapper.ToParticipant(attendee)), Encoding.UTF8, "application/json")); if (Res.IsSuccessStatusCode) { var EmpResponse = Res.Content.ReadAsStringAsync().Result; var result = JsonConvert.DeserializeObject<EmailTemplateDTO>(EmpResponse); if (result.NotError == false)return Json(new { success = false, message = Constants.CulqiResponses[result.Response] }, JsonRequestBehavior.AllowGet); if (string.IsNullOrEmpty(result.InvoiceInstitution)) { if (result.SendEmail == true) MailHelper.SendMail(Enumerables.MailAction.EventRegisterSuccess, result); return Json(new { success = true }, JsonRequestBehavior.AllowGet); }在 Web 應(yīng)用程序中,我有一個(gè) AJAX 來執(zhí)行對(duì)使用參數(shù)的所述控制器的調(diào)用async: true,但我總是收到 500 錯(cuò)誤。我不太明白原因以及我應(yīng)該如何正確調(diào)用每個(gè)方法和類以獲得正確的結(jié)果。答案如下:An asynchronous module or handler completed while an asynchronous operation was still pending.但是發(fā)送電子郵件沒有任何不便。發(fā)送電子郵件的方法必須具有以下內(nèi)容public static async void SendMail,我不希望控制器有任何真正的回應(yīng)。
異步方法返回 500 Internal Server Error 以查看,即使它完成后
寶慕林4294392
2021-11-07 19:42:40