I have an ASP.NET web api app using JavaScript to open a link to a PDF file on a server. After opening I delete the file from the server. Using Firefox, Safari and IE I am able to see the file on the browser even after the file is deleted. When I run the function in Chrome I see no file and a 404 error displayed. How can I make this functionality work in Chrome as well?
Put Method in C# to delete PDF
public void Put([FromBody]string filepath)
{
string pdfGUID_DIR = filepath.Split('/')[0]; //get the first part of the dir which is the folder name (GUID value)
string tempDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, System.Configuration.ConfigurationManager.AppSettings["TemporaryDirectoryParent"], pdfGUID_DIR + @"\");
try
{
Directory.Delete(tempDir, true);
}
catch (IOException)
{
Directory.Delete(tempDir, true);
}
catch (UnauthorizedAccessException)
{
Directory.Delete(tempDir, true);
}
}
JS Code to Open PDF
window.open('/Report/' + pdfURL); //Link to PDF file on server
setTimeout(removePDF(pdfURL), 1000);
JS Function with AJAX call to delete PDF
function removePDF(pdfURL) {
$.ajax({
url: '/api/pdf',
type: 'PUT',
data: "=" + pdfURL,
});
}