使用C#/ Asp.Net如何在重定向之前完成请求
我有一个应用程序发送到Web服务。返回时有一对夫妇的事情发生:
void Cleanup(Response response)
{
// My web service takes up to 30 seconds
// then this method is called
// I send this email
var email = SaleEmail.Create(
response.ID
DateTime.Now,
"A sale was made!");
email.Send();
// Then redirect
Response.Redirect(response.RedirectUrl, false);
Context.ApplicationInstance.CompleteRequest();
}
的想法是,在网络服务的邮件发送完毕,那么页面重定向。
此前,我使用了正常的重定向 - 结果是90%的电子邮件从未发送过。
我改变了重定向模式,但它仍然不完美 - 我猜25%的电子邮件仍然没有通过。
任何人都建议我对模式有任何改进?
电子邮件代码:
public static void Send(MailMessage message)
{
Guard.Argument.NotNull(() => message);
var c = new SmtpClient();
try
{
c.Send(message);
}
catch (Exception ex)
{
}
finally
{
c.Dispose();
message.Dispose();
}
}
你使用smtpClient? –
我使用WebClient,但这不是问题 - 如果我删除重定向一切工作正常。我曾经显示一个启动画面,让用户重定向自己,但不再可能。 –
我在说使用smtpClient发送邮件? –