简体   繁体   中英

Access to the path * is denied

I have two WebServices that create files at the same director using the following method:

var schemaDir = _propClass.RepositorySettingRoot + @"\" + webServiceId;
if (!Directory.Exists(schemaDir))
{
     Directory.CreateDirectory(schemaDir);
}
var schemaFile = schemaDir + @"\" + webMethodId + ".txt";
File.WriteAllText(schemaFile, webMethodSchema);

When trying to delete the file using File.Delete, if it was created by the 1st service it's deleted properly, but if it was created using the second, the exception Access to the path * is denied is raised.

The deletion code

schemaDir = _propClass.RepositorySettingRoot + @"\" + webServiceId + @"\" + webMethodId + ".txt";
if (File.Exists(schemaDir))
{
    File.Delete(schemaDir);
}

I've found the answer .. It's a security issue. The file should be deleted by the service created it. The deletion method was on ws1, so it can delete only the files it created.

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