我刚按照以下说明here。
但我仍然在使用HTTPS端点在Azure上运行的ASP.NET MVC3应用程序遇到奇怪的问题。我已经加载了HTTPS证书,并且已经在单个角色实例上一致地部署了很长时间而没有任何问题。但是,就在最近我开始部署多个实例并遇到“密钥无法在指定状态下使用”,并且“值不能为空”。参数名称:证书'错误。
但我现在有一个新的:
'无法在流的末尾阅读。'
看起来非常香草味。从您看到堆栈跟踪之前,从DPAPI到RSA cookie的转换问题并不明显。
[EndOfStreamException:无法读取超出流的末尾。] System.IO.MemoryStream.InternalReadInt32()+ 12750266 Microsoft.IdentityModel.Web.RsaEncryptionCookieTransform.Decode(Byte [] encoded)+369 Microsoft.IdentityModel.Tokens.SessionSecurityTokenHandler.ApplyTransforms(Byte [] cookie,Boolean outbound)+189 Microsoft.IdentityModel.Tokens.SessionSecurityTokenHandler.ReadToken(XmlReader reader,SecurityTokenResolver tokenResolver)+862 Microsoft.IdentityModel.Tokens.SessionSecurityTokenHandler.ReadToken(Byte []标记,SecurityTokenResolver tokenResolver)+109 Microsoft.IdentityModel.Web.SessionAuthenticationModule.ReadSessionTokenFromCookie(Byte [] sessionCookie)+356 Microsoft.IdentityModel.Web.SessionAuthenticationModule.TryReadSessionTokenFromCookie(SessionSecurityToken& sessionToken)+123 Microsoft.IdentityModel.Web.SessionAuthenticationModule.OnAuthenticateRequest(Object sender,EventArgs eventArgs)+61 System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()+80 System.Web.HttpApplication.ExecuteStep(IExecutionStep step,Boolean& completedSynchronously)+270
我已将以下代码添加到global.asax:
void OnServiceConfigurationCreated(object sender, ServiceConfigurationCreatedEventArgs e)
{
//
// Use the <serviceCertificate> to protect the cookies that are sent to the client.
//
List<CookieTransform> sessionTransforms = new List<CookieTransform>(
new CookieTransform[] {
new DeflateCookieTransform(),
new RsaEncryptionCookieTransform(e.ServiceConfiguration.ServiceCertificate) });
SessionSecurityTokenHandler sessionHandler = new SessionSecurityTokenHandler(sessionTransforms.AsReadOnly());
e.ServiceConfiguration.SecurityTokenHandlers.AddOrReplace(sessionHandler);
}
以及此代码:
void WSFederationAuthenticationModule_RedirectingToIdentityProvider(object sender, RedirectingToIdentityProviderEventArgs e)
{
// In the Windows Azure environment, build a wreply parameter for the SignIn request
// that reflects the real address of the application.
HttpRequest request = HttpContext.Current.Request;
Uri requestUrl = request.Url;
StringBuilder wreply = new StringBuilder();
wreply.Append(requestUrl.Scheme); // e.g. "http" or "https"
wreply.Append("://");
wreply.Append(request.Headers["Host"] ?? requestUrl.Authority);
wreply.Append(request.ApplicationPath);
if (!request.ApplicationPath.EndsWith("/")) wreply.Append("/"); e.SignInRequestMessage.Reply = wreply.ToString();
}
答案 0 :(得分:0)
我最近研究过类似的问题,可能的原因是旧版SDK和ACS的结合。如果你尝试使用SDK 1.6和ACSv2设置,我希望不会发生这个问题,如果你仍然看到问题,我很乐意与你合作以解决问题。