首页 > 解决方案 > 个性化 ASP.NET MVC OutputCache

问题描述

我有 ASP.NET MVC 应用程序,我使用 outputcache。我需要从 ip 确定国家代码并将其传递给 GetVaryByCustomString 方法。我能做什么?

[OutputCache(Duration = 3600, VaryByCustom = "none", VaryByParam = "none")]
public ActionResult Index(string amp)
{
    //i need to pass this variable to GetVaryByCustomString
    var countryCode = myService.GetCountryCode(myIpAddress);

    return View();
}

public override string GetVaryByCustomString(HttpContext context, string arg)
{
    var application = context.Application;
    var request = context.Request;
    
    
    //I need here country code 
    
    var sb = new StringBuilder();
    sb.Append(countryCode);
    
    return sb.ToString();
}

标签: c#asp.netasp.net-mvccachingoutputcache

解决方案


推荐阅读