File is locked after HttpPostedFile SaveAs(Locatio

2019-07-20 13:27发布

I have an aspx webpage that uses as handler to save uploaded files via swfupload I am saving the file on the server like this:

HttpPostedFile uploadedFile = Request.Files["Filedata"];
uploadedFile.SaveAs(LocationOnServer);

the problem is that after I save the file the file remain locked (by w3wp.exe) until I restart the IIS. Is there any way to release the file after save? Thanks

4条回答
做个烂人
2楼-- · 2019-07-20 13:50

I have dealt with the same situation in the past. You need to run your application pool under a domain account. That is, the app pool under which your web application is running should be setup to run as a domain user. That same domain user should then be given permissions to the folder you are trying to upload to. In order to assign a domain user to your application pool, select the appropriate pool from the application pools node in IIS, right click and select properties. From the properties dialog box select the identity tab and choose "Configurable" and then provide a domain account. Then you should give permissions to the same user on your folder.

查看更多
看我几分像从前
3楼-- · 2019-07-20 13:50

I cannot find any documentation but you might have to dispose of the HttpPostedFile object. Most of the time, if files are locked, then some object that associates with them has not been properly disposed.

查看更多
forever°为你锁心
4楼-- · 2019-07-20 13:59

Did you try calling Finalize() on it? Do you have any anti-virus or backup software that might be trying to grab the file?

I don't think permissions is the problem because if you didn't already have permissions to that folder you couldn't write the file to it in the first place.

查看更多
聊天终结者
5楼-- · 2019-07-20 14:06

I would check the folder permissions on the server. I had a similar issue where the application was able to create the file but not write to it, which caused it to lock up.

查看更多
登录 后发表回答