6

我已经为 asp.net 4.0 应用程序实现了 ADFS 身份验证。我已经使用 webfarm 配置在生产环境中托管了该应用程序。该网站运行良好,所有图像都在 IE8 浏览器中正确呈现。但是当我尝试在 Safari 浏览器中浏览应用程序时,网站有时无法正常工作,并且图像也无法正确呈现。

通过使用 Fiddler,我发现有时图像无法正确渲染,并且出现以下错误:

Exception information:
Exception type: XmlException
Exception message: Unexpected end of file. Following elements are not closed: Cookie, SecurityContextToken. Line 1, position 2998.

Thread information:
    Thread ID: 12
    Thread account name: CT\acmeweb
    Is impersonating: False
    Stack trace:    at System.Xml.XmlExceptionHelper.ThrowXmlException(XmlDictionaryReader reader, String res, String arg1, String arg2, String arg3)
   at System.Xml.XmlExceptionHelper.ThrowUnexpectedEndOfFile(XmlDictionaryReader reader)
   at System.Xml.XmlBaseReader.MoveToEndOfFile()
   at System.Xml.XmlUTF8TextReader.Read()
   at System.Xml.XmlDictionaryReader.ReadContentAsChars(Char[] chars, Int32 offset, Int32 count)
   at System.Xml.XmlBaseReader.ReadBytes(Encoding encoding, Int32 byteBlock, Int32 charBlock, Byte[] buffer, Int32 offset, Int32 byteCount, Boolean readContent)
   at System.Xml.XmlBaseReader.ReadContentAsBase64(Byte[] buffer, Int32 offset, Int32 count)
   at System.Xml.XmlDictionaryReader.ReadContentAsBytes(Boolean base64, Int32 maxByteArrayContentLength)
   at System.Xml.XmlDictionaryReader.ReadContentAsBase64(Int32 maxByteArrayContentLength, Int32 maxInitialCount)
   at System.Xml.XmlBaseReader.ReadContentAsBase64()
   at System.Xml.XmlDictionaryReader.ReadElementContentAsBase64()
   at Microsoft.IdentityModel.Tokens.SessionSecurityTokenHandler.ReadToken(XmlReader reader, SecurityTokenResolver tokenResolver)
   at Microsoft.IdentityModel.Tokens.SessionSecurityTokenHandler.ReadToken(Byte[] token, SecurityTokenResolver tokenResolver)
   at Microsoft.IdentityModel.Web.SessionAuthenticationModule.ReadSessionTokenFromCookie(Byte[] sessionCookie)
   at Microsoft.IdentityModel.Web.SessionAuthenticationModule.TryReadSessionTokenFromCookie(SessionSecurityToken& sessionToken)
   at Microsoft.IdentityModel.Web.SessionAuthenticationModule.OnAuthenticateRequest(Object sender, EventArgs eventArgs)
   at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

然后我尝试按照下面提到的链接:

http://social.msdn.microsoft.com/Forums/en/Geneva/thread/ea00ec3f-ebdf-427c-929f-d4a196650552

但它也没有为我工作。然后我尝试在 webfarm 配置中停止一台服务器,然后发现该网站在 IE8 和 Safari 浏览器中运行良好。在 IE8 浏览器中,它始终可以正常工作,并且所有图像都可以正确呈现,但 Safari 浏览器不会在 webfarm 中的两个服务器都打开的情况下。

经过分析,我发现从 ADFS 我得到了一些 cookie 形式的索赔信息,并且 cookie 的长度更多。对于 IE8 浏览器,cookie 长度更长,对于 Safari,允许的限制是 4097 个字符。

因此,我想到了最大化 Safari 浏览器的 cookie 限制。

任何人都可以通过提供任何代码示例来帮助我解决这个问题。

谢谢和问候, 桑托什·库马尔·帕特罗

4

2 回答 2

3

现在通过在 webfarm 场景中的负载均衡器上启用持久性 cookie(粘性会话)解决了这个问题。

于 2012-02-03T07:20:01.593 回答
2

我通过减少从 STS 返回的索赔数量来处理这个问题。这将减小 cookie 的大小。我推导出了另一种方法来通过我实现的服务获取我需要的数据。

于 2013-03-27T20:05:10.887 回答