【发布时间】:2018-04-04 15:36:08
【问题描述】:
我正在开发一个使用声明身份验证的 Web 应用程序,但我遇到了一个问题,即每当有人刷新页面时,它就会丢弃已登录的用户。这听起来与这里的问题非常相似:https://www.sitefinity.com/developer-network/forums/developing-with-sitefinity-/httpcontext-current-user-identity-isauthenticated-is-false-after-response-redirect 但不幸的是,我不能只切换到基于表单的身份验证,因为我还需要使用 openid 的东西来连接到 facebook 等。
我的 global.asax.cs 中有以下代码
protected void Application_Start(object sender, EventArgs e)
{
Telerik.Sitefinity.Abstractions.Bootstrapper.Initialized += Bootstrapper_Initialized;
// RegisterWebApiFilters(GlobalConfiguration.Configuration.Filters);
System.Web.Helpers.AntiForgeryConfig.UniqueClaimTypeIdentifier = System.Security.Claims.ClaimTypes.NameIdentifier;
}
protected void Application_AuthenticateRequest(object sender, EventArgs e)
{
var identity = System.Web.HttpContext.Current.User.Identity as System.Security.Claims.ClaimsIdentity;
var claimsUser = ClaimsManager.GetCurrentIdentity();
//identity.AddClaim(new System.Security.Claims.Claim("http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider", identity.Name));
identity.AddClaim(new System.Security.Claims.Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier", identity.Name));
//System.Web.Helpers.AntiForgeryConfig.UniqueClaimTypeIdentifier = System.Security.Claims.ClaimTypes.NameIdentifier;
}
上面代码中的标识变量在重新加载页面之前显示登录用户正常,包括它存储在 cookie 中,但在重新加载时返回为匿名用户。
我想我也正确配置了 web.config。我将身份模型设置为以下内容:
<system.identityModel.services>
<federationConfiguration>
<wsFederation passiveRedirectEnabled="true" issuer="http://localhost" realm="http://localhost" requireHttps="false" />
<cookieHandler requireSsl="false" />
</federationConfiguration>
任何想法都将不胜感激。
【问题讨论】: