简体   繁体   中英

How to update files in a site on IIS via the site?

Okay, so we have a CMS site in IIS, running on ASP.NET 4.0.

The user wants to update some images on the site, but because they have been recently served up, IIS has a handle open to them, locking the files. This leads to the user receiving the error below when trying to upload an updated version of the file:

The process cannot access the file 'X:\inetpub\wwwroot\sitename\Images\Banner\Temp\5.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:\inetpub\wwwroot\sitename\Images\Banner\Temp\5.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:\inetpub\wwwroot\sitename\Images\Banner\Temp\5.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

Is there any way, programmatically in the ASP.NET code to tell IIS to release it's cached handles to the file so that it may be updated? Obviously, recycling the whole IIS process is not really a workable approach here.

Bro, I do not think you have diagnosed the problem correctly. IIS never holds back files this way, and I am quite sure that this is not the case.

Have you been playing around with these images in your code somewhere, like modifying/show them using Bitmap classes of .Net? I think your own code is holding back these images. If you can paste your code in here, I might be of any help.

Restarting is the best and worst option available. you can give it another try by deploying updated global.asax

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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