Выходной кэш пользователем, использующим сеанс - PullRequest
1 голос
/ 12 июня 2019

Мне нужно повысить производительность моего сайта.поэтому мне нужно поместить данные в кэш вывода в c # на основе данных отдельных пользователей, использующих сессию.

На самом деле я использую GetVaryByCustomString в global.asax для назначения имени пользователя параметру в выходном кеше.но сеанс не работает методы GetVaryByCustomString.

C #: -

[OutputCache(CacheProfile = "Dashboard")]
  public ActionResult Index()
  {}

Web.config: -

<caching>
      <outputCacheSettings>
        <outputCacheProfiles>
          <add name="Dashboard" duration="86400" varyByParam="*" varyByCustom="User" location="Server" />
        </outputCacheProfiles>
      </outputCacheSettings>
    </caching>

Global.asax: -

public override string GetVaryByCustomString(System.Web.HttpContext context, string arg)
        {
            if (arg == "User")
            {
                if (this.Session != null)
                    // depends on your authentication mechanism
                    return "User=" + context.Session;
                //?return "User=" + context.Session.SessionID;
            }


            return base.GetVaryByCustomString(context, arg);
        }

состояние сеанса недоступнов этом контексте

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...