cshtml being cached, need to restart web.config for every change

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
4 years ago
Hi,

I am facing a difficulty when changing cshtml as I need to save web.config in order to see the HTML changes (please note this is not browser's cache).

Has anyone found a better way to refresh the cache after editing cshtml files avoiding long waiting?

Thank you in advance.
4 years ago
is this in a Dev or Production environment?  

In published environments I believe the cshtml files are compiled at runtime, so restarting the application should recompile the changes.  I think this addresses it: https://docs.microsoft.com/en-us/aspnet/core/mvc/views/view-compilation?view=aspnetcore-3.1

In Dev you may need to do a force refresh depending on browser (ctrl+F5)
4 years ago
I think restarting the web application using IIS would be easier than changing the web.config file to restart the application.
4 years ago
This change has been made in ASP.NET Core 2.2. However you can turn off this by using some configuration in your Startup class.

services.AddMvc().AddRazorOptions(options => options.AllowRecompilingViewsOnFileChange = true);


The value of AllowRecompilingViewsOnFileChange determines whether to watch for file changes (on disk) or not. When it's true, MVC will watch for changes to cshtml files.

By default, the value is true for ASP.Net Core 2.1 or earlier, as well as the Development environment of later versions.  Otherwise the value is false.
3 years ago
You can also enable the Development-Environment via web config environmentVariable. This is much easier than modifying any code.


<configuration>
  <system.webServer>
    <aspNetCore ...>
      <environmentVariables>
        <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
      </environmentVariables>
    </aspNetCore>
  </system.webServer>
</configuration>
3 years ago
Using NOP 4.2 with no source code.
Can you point me where to find the "Startup Class" to be edited "options.AllowRecompilingViewsOnFileChange = true"?

Or how to view .cshtml changes without IIS restart in the no source code.

Thanks!

services.AddMvc().AddRazorOptions(options => options.AllowRecompilingViewsOnFileChange = true);
3 years ago
BenjaminFreitag wrote:
You can also enable the Development-Environment via web config environmentVariable. This is much easier than modifying any code.


<configuration>
  <system.webServer>
    <aspNetCore ...>
      <environmentVariables>
        <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
      </environmentVariables>
    </aspNetCore>
  </system.webServer>
</configuration>


That works great, thanks. nopVersion Version 4.20
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.