Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/331.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# 使用VaryByCustom使缓存无效_C#_Asp.net Mvc 4_Caching_Cache Invalidation - Fatal编程技术网

C# 使用VaryByCustom使缓存无效

C# 使用VaryByCustom使缓存无效,c#,asp.net-mvc-4,caching,cache-invalidation,C#,Asp.net Mvc 4,Caching,Cache Invalidation,我想使用VaryByCustom属性使缓存无效。 以下代码用于缓存设置 public override string GetVaryByCustomString(HttpContext context, string arg) { if (!string.IsNullOrWhiteSpace(arg)) { if (context.User.Identity.Name != null) { return context.Us

我想使用VaryByCustom属性使缓存无效。 以下代码用于缓存设置

public override string GetVaryByCustomString(HttpContext context, string arg)
{
    if (!string.IsNullOrWhiteSpace(arg))
    {
        if (context.User.Identity.Name != null)
        {
            return context.User.Identity.Name;
        }
    }
    return base.GetVaryByCustomString(context, arg);
}

您是这样使用它的:

确保使用以下属性装饰您的操作:

 [OutputCache(Duration = 3600, VaryByParam = "*", Location = OutputCacheLocation.Server, VaryByCustom = 
  "YourStringThatIsArgParamInYourGlobalAsaxMethod")]
  public ActionResult MyActionOnTheController(string myParam)
 {
 }

那么,你把代码放在哪里了,什么不起作用了?我把它放在了Global.asx中。我想根据该方法作为arg获取的VaryByCustom属性使缓存基无效。