此代码在localhost / IIS express上完美运行。我收到附带pdf的电子邮件。但是,当我将它复制到我的服务器IIS7时,它失败了。有什么想法吗?
var db = new DirectCellarsModel();
var status = false;
MailAddress from = new MailAddress(EMAIL_SENDER);
MailAddress to = new MailAddress(recipient);
MailMessage message = new MailMessage(from, to);
message.Subject = subject;
message.Body = messageBody;
if (pdf)
{
Attachment data = new Attachment(@"C:\develop\PDF\myfree.pdf", MediaTypeNames.Application.Octet);
message.Attachments.Add(data);
}
SmtpClient client = new SmtpClient(SMTP_CLIENT);
这是错误消息:
The device is not ready.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IO.IOException: The device is not ready.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
IOException: The device is not ready.
System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +1093
System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) +886
System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share) +127
System.Net.Mail.AttachmentBase.SetContentFromFile(String fileName, String mediaType) +104
答案 0 :(得分:0)
错误Device Not Ready
通常表示给定的位置不存在。通常这意味着驱动器本身不存在,但在这种情况下,我无法想象服务器没有C驱动器(但可能没有,服务器可以从另一个设备启动)。检查以确保驱动器和驱动器上的文件夹确实存在。
请查看此答案以获取有关调试和其他可能问题的提示:
'device not ready' while using File.Copy() in C#
如果该位置确实存在,请检查用户是否有权阅读该位置。匿名用户由IUser
标识。
答案 1 :(得分:0)
即使位置" C:\ develop \ PDF \"存在于服务器上,您的IIS_USER帐户(或其他帐户)可能没有访问该位置的完全权限的帐户。
您可能需要考虑在网站的根目录下设置子文件夹,并使用IIS帐户的相关权限轻松访问。