Don Rhummy
Don Rhummy

Reputation: 25830

How make ASP.Net recompile page on changes?

I created an aspx page and viewed it in Firefox and Chrome and it worked correctly, running the C# code. But when I make changes to the page (including deleting everything and serving up a blank page), both browsers continue to show the original compiled aspx page!

It appears that ASP.Net (the web server) is not recompiling despite changes to the aspx file. The only way to get it to recompile is to change web.config and then restart the web server!

I even added the following code, but it still loads the original page:

<script runat="server">
Sub Page_Load
    Random rd = new Random();
    Response.AddHeader("ETag", rd.Next(1111111, 9999999).ToString());
    Response.AddHeader("Pragma", "no-cache");
    Response.CacheControl = "no-cache";
    Response.Cache.SetNoStore();
    Response.Expires = -1;
End Sub
</script>

TEST I DID TO RULE OUT BROWSER CACHING:

  1. Created an aspx page and loaded it in firefox only (not in chrome)
  2. Changed the aspx file
  3. Loaded aspx again in firefox but got no changes
  4. Loaded it (for the first time ever) in Chrome and it still showed the old version!

Using Apache and Mono, not IIS

Upvotes: 2

Views: 2769

Answers (3)

Don Rhummy
Don Rhummy

Reputation: 25830

This appears to be a Mono+Apache on Linux issue. It doesn't see changes to pages that have been compiled. The only workarounds are:

  1. Restart Apache webserver (this causes it to see them as changed) - only takes about 2 seconds

  2. Delete the temporary files in "/tmp/www-data-temp-aspnet-0/" (This can be a bit buggy so #1's a better choice)

Upvotes: 2

user215054
user215054

Reputation:

Short Answer: It is browser's fault, and it is expected behavior by design. Force cache refresh in browsers (Ctrl-F5 in IE).

Correction: When it is Mono/Apache stack, not an IIS. Then manual restarts can be the only workaround. In IIS the stale effects are naturally cleared in between periods of inactivity, when server kills idle processes. In Mono, there may or may not be same cleaning schedule, so, the process lifecycle and configs are the first place to look at for fix.

The behavior of not recompiling is caused by complex identity of requested pages. Identity includes URL, timestamp and session. If you trying to refresh page without closing the browser, then ASP server will need to serve a stale copy of older compiled page, because server tries to maintain consistency of served page with existing session, viewstate, perhaps even client side scripts wich exist on client in between partial updates, etc. Also browsers are designed to comply to slowly changed internet pages with storing copies in cache and maintaining the age of copies to skip unnecessary network trips. Or else internet would be 10 times slower.

Other note: The most slow files to push through ASP server are css files.

Upvotes: 0

AYK
AYK

Reputation: 3322

Check whether your web application is a Web Application project or a Web Site project. If it was a Web Application, you will need to compile each time you change something, whereas web site projects allow changes to get reflected without compilation. Also, you can use Ctrl+F5 in browsers to get a non-cached copy of pages. Hope his helps.

Read details here

Upvotes: 0

Related Questions