在联合身份令牌上获取“不是有效的Base-64字符串”

浏览我的mvc3 azure web角色时,我随机得到一个base 64编码错误。 我正在使用带有被动身份validation的WIF来对我的ADFS服务器进行身份validation。 我无法隔离它的来源,但我有一个想法,并希望得到一些反馈/帮助。

从调用堆栈看起来它来自一个糟糕的cookie。 当我从chrome开发者控制台查看我的cookie时,来自wif / adfs的“FedAuth”cookie是唯一出现的。 所以我想这些cookie已经被破坏或者其中包含无效字符。 我正在努力validation这一点,但由于错误是随机发生的,所以需要一些时间。 有没有人经历过类似的事情,或者有什么倾向可能导致这种情况? 任何帮助表示赞赏!

这是例外:

The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or a non-white space character among the padding characters. [FormatException: The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or a non-white space character among the padding characters. ] System.Convert.FromBase64String(String s) +0 Microsoft.IdentityModel.Web.ChunkedCookieHandler.ReadInternal(String name, HttpCookieCollection requestCookies) +613 Microsoft.IdentityModel.Web.ChunkedCookieHandler.ReadCore(String name, HttpContext context) +174 Microsoft.IdentityModel.Web.CookieHandler.Read(String name, HttpContext context) +133 Microsoft.IdentityModel.Web.CookieHandler.Read(HttpContext context) +59 Microsoft.IdentityModel.Web.CookieHandler.Read() +65 Microsoft.IdentityModel.Web.SessionAuthenticationModule.TryReadSessionTokenFromCookie(SessionSecurityToken& sessionToken) +84 Microsoft.IdentityModel.Web.SessionAuthenticationModule.OnAuthenticateRequest(Object sender, EventArgs eventArgs) +119 System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +80 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +270 

我一直在对我的cookie进行更多测试,我可以看到每次请求我的fedauth cookie变得越来越大。 这可能是部分或全部问题。 最终,随机的东西会附加一些不好的字符。 令牌以这些关闭标签“”结束。 我可以看到,在安全上下文令牌关闭标记之后出现一些额外的字符时,它会失败。 每次发生错误时,额外字符都不同。

弄清楚了。 Opps …程序员错误……

当用户首次登录我的应用程序时,我会从我的数据库中提取一些角色信息并为其创建声明。 我每次都重新添加这些声明,所以我的会话令牌正在增长……并且正在增长…最终这导致令牌分裂2,3,4,5,6个cookie并且最终有些东西只是窒息这个。 我不再每次都添加索赔。 不再看到这个问题。

感谢你的帮助。

我有一个类似的错误消息使用base64来编码查询字符串中的参数,我有一个%3d在查询字符串中显示正常,但是当我在代码中检索它时,asp.net将其转换为=符号。 我在解密base64之前通过调用Server.UrlEncode()来解决它。 可能是cookie中的base64值在被解密之前被解码。