c# - 个性化 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();
}
解决方案
推荐阅读
- ios - 如何使一个标签在另一个标签的前导约束之前显示多行?
- c++ - 在 C++ 中获取指针的真实类型信息
- c++ - 计算字符串中某些字符的数量
- rabbitmq - 安装rabbitMQ后无法运行我的ubuntu 20.04
- c# - Unity Mirror Multiplayer RTS,客户端忽略 hasAuthority 检查
- javascript - 如果指定了文本颜色,则禁用按钮在 React JS 中不起作用
- powershell - Powershell:在两列数组中获取唯一对象
- powershell - 从文件 20.0.0.1 到 20.0.0.21 的函数搜索
- php - 如何在颤动的firebase云消息数组中获取成功消息
- c++ - 为什么将 std::mutex 引入成员类会产生此编译错误?