我建议您使用用于该站点的 SSL 证书来加密会话 cookie,并为运行 IIS 应用程序池的用户授予对该证书的私钥的访问权限。
您可以通过以下方式实现前者:
首先,在您的 Application Start 事件中,连接 onServiceConfigurationCreated 事件:
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
FederatedAuthentication.ServiceConfigurationCreated += OnServiceConfigurationCreated;
}
然后使用以下实现:
void OnServiceConfigurationCreated(object sender, ServiceConfigurationCreatedEventArgs e)
{
//
// Use the <serviceCertificate> to protect the cookies that are
// sent to the client.
//
if (e.ServiceConfiguration.ServiceCertificate != null)
{
List<CookieTransform> sessionTransforms =
new List<CookieTransform>(new CookieTransform[] {
new DeflateCookieTransform(),
new RsaEncryptionCookieTransform(e.ServiceConfiguration.ServiceCertificate),
new RsaSignatureCookieTransform(e.ServiceConfiguration.ServiceCertificate) });
SessionSecurityTokenHandler sessionHandler =
new SessionSecurityTokenHandler(sessionTransforms.AsReadOnly());
e.ServiceConfiguration.SecurityTokenHandlers.AddOrReplace(sessionHandler);
}
您需要在 microsoft.identityModel 部分的 Certificates 部分中添加该证书:
<serviceCertificate>
<certificateReference x509FindType="FindByThumbprint" findValue="[cert_thumbprint]" />
</serviceCertificate>
最后,要向运行 App Pool 的用户授予对该证书的私钥的访问权限,请使用:
winhttpcertcfg -g -a "AppPool 账户" -c LOCAL_MACHINE\My -s www.mysite.com
其中,winhttpcertcfg是从这里下载的工具。LOCAL_MACHINE\My证书存储的名称,SSL 证书被定位。“ www.mysite.com ” 是 SSL 证书的主题 (CN) 名称。
我认为这将解决您的问题。如果没有,请带着结果返回这里。