Search code examples
c#asp.netiisiis-10

IIS is not refreshing files after I downloaded it once?


We have an asp.net website, with a folder called templates with Summaries.xlsx and Totals.txt. The website has a link for the user to view these files.

After downloading Summaries.xlsx to my PC (ie. a copy was downloaded to my local Downloads folder), I decided to edit the original file where the website is set up. Even after editing and saving in the IIS folder, I'm still downloading the old version without the changes.

On the other hand, as soon as I edit the text file (which is displayed in the browser and is not "downloaded" to my local Downloads folder), I see the update.

The same thing happens if I erase both files from the server: I can still download the Excel file (that doesn't exist) but the txt file will display a 404 error.

I know it's a cache issue, But I can't ask all the users to clear their browser cache.

I tried the solution in this forums.iis.net link, but it didn't help.

I've also tried recycling the App Pool, and nothing.

Finally, I installed Application Request Routing Cache but I don't see Delete All Cached Objects in the Actions pane.


Solution

  • Assuming the asp:HyperLink is in the Content Page. you can create a javascript function and call it inside the NavigateUrl attribute

    <asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
       
        <script type="text/javascript">
            function DownloadFile(url) {
                document.location.href = url + "?dt=" + (new Date()).getTime();
            }
        </script>
    
    
        <asp:HyperLink runat="server" NavigateUrl="javascript:DownloadFile('/Templates/Summaries.xlsx')"> Summaries </asp:HyperLink>
    
    </asp:Content>