【发布时间】:2016-07-29 14:35:33
【问题描述】:
我正在使用代码 FederatedAuthentication.SessionAuthenticationModule.WriteSessionTokenToCookie(token); 为网站创建身份验证 cookie
令牌相当大,所以 cookie 被分成两个 cookie。 99% 的情况下一切正常,以下是成功登录后的两个 cookie 的示例,这些 cookie 已被 Base64 解码:
网站验证:
<?xml version="1.0" encoding="utf-8"?><SecurityContextTokenp1:Id="_e00ce4ab-> 2439-48d3-a1cd-f6a31180d02f-B99934A3DBEDB9B3EA191AB595FA8011" xmlns:p1="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns="http://docs.oasis-open.org/ws-sx/ws-secureconversation/200512"><Identifier>urn:uuid:adbfc4e1-c4a1-4882-9980-aa59431cdf48</Identifier><Cookie xmlns="http://schemas.microsoft.com/ws/2006/05/security">ENCRYPTED_COOKIE_VALUE
WebSiteAuth1:
ENCRYPTED_COOKIE_VALUE</Cookie></SecurityContextToken>
但有时用户会遇到以下错误:
异常信息: 异常类型:FormatException 异常消息:输入不是有效的 Base-64 字符串,因为它包含非 base 64 字符、两个以上的填充字符,或 填充字符中的非法字符。在 System.Convert.FromBase64_Decode(Char* startInputPtr, Int32 inputLength, Byte* startDestPtr, Int32 destLength) 在 System.Convert.FromBase64CharPtr(Char* inputPtr, Int32 inputLength)
在 System.Convert.FromBase64String(String s) 在 System.IdentityModel.Services.SessionAuthenticationModule.TryReadSessionTokenFromCookie(SessionSecurityToken& sessionToken) 在 System.IdentityModel.Services.SessionAuthenticationModule.OnAuthenticateRequest(对象 发件人,EventArgs eventArgs)在 System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() 在 System.Web.HttpApplication.ExecuteStep(IExecutionStep 步骤, Boolean & completedSynchronously)
我在引发错误时记录了用户的 cookie,这是我对它们进行 Base64 解码后的 cookie 的样子。
网站验证:
<?xml version="1.0" encoding="utf-8"?><SecurityContextToken p1:Id="_3518f851-bbec-4bb3-b7bb-c4c9bd9165e2-978AD0895E2683747B7CAFF4F1C7131B" xmlns:p1="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns="http://docs.oasis-open.org/ws-sx/ws-secureconversation/200512"><Identifier>urn:uuid:dd9a6856-9bd1-486c-9f5c-e980fbcc3b02</Identifier><Cookie xmlns="http://schemas.microsoft.com/ws/2006/05/security">ENCRYPTED_COOKIE_VALUE</Cookie></SecurityContextToken>
WebSiteAuth1:
ENCRYPTED_COOKIE_VALUE</Cookie></SecurityContextToken>
如您所见,不同之处在于第一个 cookie 有结束标签 </Cookie></SecurityContextToken>,它不应该在那里,因为 xml 在第二个 cookie 中是关闭的。
我认为这是导致错误的原因。
有人遇到过这个问题吗?或者有什么想法可以解决这个问题?
【问题讨论】:
标签: c# asp.net-mvc-4