好的,所以我们在IIS中有一个CMS站点,运行在 ASP.NET 4.0上。
用户想要更新网站上的一些图像,但由于它们最近已提供,IIS 会打开一个句柄,锁定文件。这会导致用户在尝试上传文件的更新版本时收到以下错误:
The process cannot access the file 'X:inetpubwwwrootsitenameImagesBannerTemp5.jpg' because it is being used by another process.
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 process cannot access the file 'X:inetpubwwwrootsitenameImagesBannerTemp5.jpg' because it is being used by another process.
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 process cannot access the file 'X:inetpubwwwrootsitenameImagesBannerTemp5.jpg' because it is being used by another process.]
System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +14328663
System.IO.File.InternalDelete(String path, Boolean checkHost) +14293114
Admin_Settings_EditHomePageBanner.btnSave_Click(Object sender, ImageClickEventArgs e) +1109
System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs e) +134
System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String eventArgument) +204
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3804
有没有办法在 ASP.NET 代码中以编程方式告诉IIS释放文件的缓存句柄,以便可以对其进行更新?显然,回收整个IIS过程并不是一个可行的方法。
兄弟,我认为您没有正确诊断问题。IIS 从不以这种方式保留文件,我很确定情况并非如此。
您是否一直在代码中的某个地方使用这些图像,例如使用 .Net 的位图类修改/显示它们?我认为您自己的代码阻碍了这些图像。如果你能把你的代码粘贴在这里,我可能会有任何帮助。
重新启动是可用的最佳和最差选项。 您可以通过部署更新的 global.asax 再试一次