[英]Two exception throws at the same time in ASP.Net MVC inside IIS, But can't see the exception
[英]Can't release file in asp.net MVC on IIS
這是我做的功能:
if (Valide())
{
try
{
File.Delete(Server.MapPath("F16client.pdf"));
}
catch
{
}
using (FileStream ms = new FileStream(Server.MapPath("F16client.pdf"), FileMode.Create, FileAccess.Write, FileShare.None))
{
PdfReader lecteur = new PdfReader(Server.MapPath("~/Formulaires/f16.pdf"));
PdfStamper etampeur = new PdfStamper(lecteur, ms);
// DO STUFF, Whatever
etampeur.FormFlattening = true;
etampeur.Close();
lecteur.Close();
System.Net.Mail.Attachment at = new Attachment(Server.MapPath("F16client.pdf"));
}
}
它在測試本地時有效,但是在IIS上,此W3W進程不會放開我的f16client.pdf,而我總是以:
該進程無法訪問文件'D:\\ inetpub \\ wwwroot \\ Formulaire16 \\ F16client.pdf',因為該文件正在被另一個進程使用。
為什么在IIS上而不是在測試本地時仍在使用該文件?
檢查IIS上應用程序池用戶的訪問權限。 然后使用以下代碼重試:
var file = Server.MapPath("F16client.pdf")
File.SetAttributes(file, FileAttributes.Normal);
File.Delete(file);
這可能是權限或文件屬性問題。
好吧...這里沒有魔術。 感謝Feryal Badili指出了問題,電子郵件附件實際上可以保留資源...
所以,一個簡單的:
at.Dispose();
在功能結束之前,一切都好。 是的
它在local上起作用的原因可能是因為每次測試時我都按下“ stop everything
按鈕,因此,每次它嘗試我的功能時,我都殺死了手柄。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.