Why are cookies unrecognized when a link is clicked from an external source (i.e. Excel, Word, etc…)

后端 未结 17 2575
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-28 04:39

I noticed that when a link is clicked externally from the web browser, such as from Excel or Word, that my session cookie is initially unrecognized, even if the link opens u

17条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-28 04:52

    Here is a solution for C# ASP.NET based on spilliton's answer above. In Global.asax.cs, add the following:

        private static string MSUserAgentsRegex = @"[^\w](Word|Excel|PowerPoint|ms-office)([^\w]|\z)";
        protected void Application_OnPostAuthenticateRequest(object sender, EventArgs e)
        {
            if (System.Text.RegularExpressions.Regex.IsMatch(Request.UserAgent, MSUserAgentsRegex))
            {
                Response.Write("");
                Response.End();
            }
        }
    

提交回复
热议问题