简体   繁体   English

SmtpClient.SendAsync在ASP.NET MVC上不起作用

[英]SmtpClient.SendAsync not working on asp.net MVC

您能建议我如何使用asp.net MVC进行异步操作吗?

EDIT 编辑

the answer below is outdated. 下面的答案已经过时。 AsyncController has been part of ASPNET MVC since v2. AsyncController一直以来V2 ASPNET MVC的一部分。

A cursory search of the internet indicates that async processing is not currently part of MVC, but it is possible to roll your own: 粗略地搜索互联网的指示异步处理当前不是MVC的一部分,但它有可能推出自己的:

http://blog.codeville.net/2008/04/05/improve-scalability-in-aspnet-mvc-using-asynchronous-requests/ http://blog.codeville.net/2008/04/05/improve-scalability-in-aspnet-mvc-using-asynchronous-requests/

Using such a pattern would then allow you to perform other async operations without tying up a thread. 然后,使用这种模式将允许您执行其他异步操作而无需占用线程。

EDIT: 编辑:

Or perhaps this near dupe question solves your problem? 还是这个近乎欺骗的问题解决了您的问题?

How to send an email with attachments using SmtpClient.SendAsync? 如何使用SmtpClient.SendAsync发送带有附件的电子邮件?

The same way as with any other platform... the fact that you're using ASP.NET MVC doesn't change anything to the way SmtpClient works. 与任何其他平台相同的方式...使用ASP.NET MVC的事实不会改变SmtpClient的工作方式。 If it doesn't work, it's probably not due to ASP.NET MVC... 如果它不工作,这可能不是由于ASP.NET MVC ...

The reseaon why not work because the close of mvc work process cancels sending the email. 为什么不能正常工作,因为mvc工作进程关闭会取消发送电子邮件。 It's nature of MVC life cycle. 这是MVC生命周期的本质。 You have to use another way. 您必须使用另一种方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM