Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ASP.NET核心:禁用浏览器缓存_C#_Asp.net_Visual Studio_Caching_Asp.net Core - Fatal编程技术网

C# ASP.NET核心:禁用浏览器缓存

C# ASP.NET核心:禁用浏览器缓存,c#,asp.net,visual-studio,caching,asp.net-core,C#,Asp.net,Visual Studio,Caching,Asp.net Core,我是一名网络开发新手,ASP.NETCore是我使用过的第一个网络框架。当我点击F5时,我注意到我的网站没有更新,我跟踪到浏览器缓存被启用。如果我打开ChromeDevTools>Network并选择“禁用浏览器缓存”,我的站点将得到正确更新 但是,我不希望每次开始调试时都经历这个过程。有没有办法在我的ASP.NET核心应用程序中以编程方式禁用缓存,例如通过Startup.cs文件,以便自动为我执行此操作 编辑:我正在使用UseFileServer而不是usesticfiles。(我不确定这两种

我是一名网络开发新手,ASP.NETCore是我使用过的第一个网络框架。当我点击F5时,我注意到我的网站没有更新,我跟踪到浏览器缓存被启用。如果我打开ChromeDevTools>Network并选择“禁用浏览器缓存”,我的站点将得到正确更新

但是,我不希望每次开始调试时都经历这个过程。有没有办法在我的ASP.NET核心应用程序中以编程方式禁用缓存,例如通过
Startup.cs
文件,以便自动为我执行此操作

编辑:我正在使用
UseFileServer
而不是
usesticfiles
。(我不确定这两种方法都能做什么,但是
UseFileServer
能够正确地进行调试,而
usesticfiles
不能。)我尝试将
FileServerOptions
参数传递给
UseFileServer
,但这不允许您像
staticfileoptions
那样配置缓存到期时间


如果相关的话,我正在构建一个Web API项目。

在使用
UseFileServer
时,您仍然可以使用
StaticFileOptions

var fsOptions = new FileServerOptions();
fsOptions.StaticFileOptions.OnPrepareResponse = (context) =>
{
    // Disable caching of all static files.
    context.Context.Response.Headers["Cache-Control"] = "no-cache, no-store";
    context.Context.Response.Headers["Pragma"] = "no-cache";
    context.Context.Response.Headers["Expires"] = "-1";
}
app.UseFileServer(fsOptions);

@I.Manev看到我更新的描述。你在浏览器上禁用缓存怎么样。浏览器有一些关键命令来绕过缓存,如ctl+F5。这是不正确的。
StaticFilesOptions
是一个只读属性。请编辑您的答案如下:
var fsOptions=new FileServerOptions();fsOptions.StaticFileOptions.OnPrepareResponse=。。。;app.UseFileServer(fsOptions)。这对我很有用。谢谢你的更新。这将教会我在没有IDE的情况下工作。