How do I configure ASP.Net OutputCache to vary by http vs https?

前端 未结 3 1405
别那么骄傲
别那么骄傲 2021-02-13 10:44

Here is the scenario, a user opens up non-secure page from our WebApp, let\'s call it PageA, in their browser and then clicks a link in there that takes them to a secure instanc

3条回答
  •  自闭症患者
    2021-02-13 11:37

    I think that you can do a VaryByCustom="scheme" and add this to your Global.asax.cs file (inlcuding a couple other others that I use as well app version & user):

        public override string GetVaryByCustomString(HttpContext context, string custom)
        {
            if (custom.Equals("version", StringComparison.CurrentCultureIgnoreCase))
            {
                Assembly asm = Assembly.GetExecutingAssembly();
                string[] parts = asm.FullName.Split(',');
                string version = parts[1].Trim().ToLower();
                return version;
            }
            else if (custom.Equals("user", StringComparison.CurrentCultureIgnoreCase))
            {
                var user = Membership.Users.CurrentUser;
                return null == user ? string.Empty : user.Id.ToString();
            }
            else if (custom.Equals("scheme", StringComparison.CurrentCultureIgnoreCase))
            {
                var scheme = context.Request.IsSecureConnection ? "https" : "http";
                return scheme;
            }
            else
                return base.GetVaryByCustomString(context, custom);
        }
    

提交回复
热议问题