Iis 7 是否可以在没有LoadUserProfile=True的情况下运行WIF
我正在尝试在共享主机上运行WIF依赖方应用程序。他们不会将IIS设置LoadUserProfile设置为true,因此我得到以下错误: 消息:数据保护操作未成功。这可能是由于没有为当前线程的用户上下文加载用户配置文件造成的,这可能是线程正在模拟的情况。例外跟踪:位于Microsoft.IdentityModel.Web.ProtectedDataCookieTransform.Encode(字节[]值)的System.Security.Cryptography.ProtectedData.Protect(字节[]用户数据,字节[]可选熵,数据保护范围)Iis 7 是否可以在没有LoadUserProfile=True的情况下运行WIF,iis-7,wif,Iis 7,Wif,我正在尝试在共享主机上运行WIF依赖方应用程序。他们不会将IIS设置LoadUserProfile设置为true,因此我得到以下错误: 消息:数据保护操作未成功。这可能是由于没有为当前线程的用户上下文加载用户配置文件造成的,这可能是线程正在模拟的情况。例外跟踪:位于Microsoft.IdentityModel.Web.ProtectedDataCookieTransform.Encode(字节[]值)的System.Security.Cryptography.ProtectedData.Pro
是否存在这种情况?是的,这是因为您使用的是依赖于DPAPI的默认令牌加密。你可以用基于证书的加密来代替它。请参见此处:(滚动至“应用程序还有一项更改…”) 代码是:
void OnServiceConfigurationCreated(object sender, ServiceConfigurationCreatedEventArgs e)
{
var sessionTransforms =
new List<CookieTransform>(
new CookieTransform[]
{
new DeflateCookieTransform(),
new RsaEncryptionCookieTransform(
e.ServiceConfiguration.ServiceCertificate),
new RsaSignatureCookieTransform(
e.ServiceConfiguration.ServiceCertificate)
});
var readOnlyTransforms = sessionTransforms.AsReadOnly();
var sessionHandler = new SessionSecurityTokenHandler(readOnlyTransforms);
e.ServiceConfiguration.SecurityTokenHandlers.AddOrReplace(sessionHandler);
}
都在global.asax.cs上
顺便说一句,这也是配置WIF的“web场友好”方式,因此它与机器(实例)无关。Windows Azure部署本质上是web场,所以这就是您在该章中看到它的原因
更新:在较新版本中,API已更改。更新后的代码如下所示
void OnFederationConfigurationCreated(object sender, FederationConfigurationCreatedEventArgs e)
{
var sessionTransforms = new List<CookieTransform>(
new CookieTransform[]
{
new DeflateCookieTransform(),
new RsaEncryptionCookieTransform(e.FederationConfiguration.ServiceCertificate),
new RsaSignatureCookieTransform(e.FederationConfiguration.ServiceCertificate)
});
var sessionHandler = new SessionSecurityTokenHandler(sessionTransforms.AsReadOnly());
e.FederationConfiguration
.IdentityConfiguration
.SecurityTokenHandlers
.AddOrReplace(sessionHandler);
}
您还可以使用.net 4.5中命名空间System.IdentityModel.Services.Tokens
中提供的。您可以通过在配置中设置此令牌处理程序来启用它
<system.identityModel>
<identityConfiguration>
<securityTokenHandlers>
<remove type="System.IdentityModel.Tokens.SessionSecurityTokenHandler,
System.IdentityModel, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=B77A5C561934E089" />
<add type="System.IdentityModel.Services.Tokens.MachineKeySessionSecurityTokenHandler,
System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=B77A5C561934E089">
</add>
</securityTokenHandlers>
</identityConfiguration>
</system.identityModel>
我已使用Visual Studio 2010在Windows Azure培训工具包实验室之后创建了一个MVC 4 Hello World应用程序。该应用程序已使用发布…发布Web功能部署到Azure。然后,我添加了一个STS引用,试图通过ACS对其进行身份验证,我在这个问题上遇到了错误。我已经添加了您的代码,并且相信我还需要在web.config中指定serviceCertificate,但我一直在想如何将证书部署到Azure网站。我在新Azure门户中找不到链接,在VS项目或发布配置文件中也找不到设置。哦,请稍候。我创建了一个Azure网站,而不是云服务。如果我创建了一个云服务(其中没有任何内容),我可以在管理门户中看到一个证书选项卡,因此我猜我使用了错误的Azure。将尝试其他实验室,然后将代码移到Azure的正确位置。这似乎是一个比其他建议更容易的答案。好极了!
protected void Application_Start()
{
FederatedAuthentication.FederationConfigurationCreated += OnFederationConfigurationCreated;
}
<system.identityModel>
<identityConfiguration>
<securityTokenHandlers>
<remove type="System.IdentityModel.Tokens.SessionSecurityTokenHandler,
System.IdentityModel, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=B77A5C561934E089" />
<add type="System.IdentityModel.Services.Tokens.MachineKeySessionSecurityTokenHandler,
System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=B77A5C561934E089">
</add>
</securityTokenHandlers>
</identityConfiguration>
</system.identityModel>