我正在使用 Windows Identity Foundation (WIF) 安全 token 服务 (STS) 来处理我的应用程序的身份验证,它运行良好。但是,我似乎无法使用 STS 获得任何长时间运行的登录。
根据我的理解,我不应该关心应用程序级别的客户端 token ,因为它们可以随心所欲地过期,它应该将我重定向到 STS,只要它们仍在 STS 上,它就应该刷新他们的应用程序 token 。然而,它似乎并不想让他们保持登录状态。
这是我在 STS 上的 login.aspx 中发生的事情
var cookie = FormsAuthentication.GetAuthCookie(userName, persistTicket);
if (persistTicket)
cookie.Expires = DateTime.Now.AddDays(14);
Response.Cookies.Add(cookie);
var returnUrl = Request.QueryString["ReturnUrl"];
Response.Redirect(returnUrl ?? "default.aspx");
这几乎是直接从使用普通 Forms Auth 的现有应用程序中获取的。
来 self 的 web.config
<authentication mode="Forms">
<forms loginUrl="Login.aspx" protection="All" timeout="2880"
name=".STS" path="/" requireSSL="false" slidingExpiration="true"
defaultUrl="default.aspx" cookieless="UseDeviceProfile"
enableCrossAppRedirects="false" />
</authentication>
在我登录后查看 cookie,我可以看到 cookie 上的过期时间设置为 future 14 天,并且该 cookie 不是 session cookie。
当我被要求重新登录到 STS 时,我可以看到我原来的 cookie 仍然存在。
STS 嵌入到 cookie 中的某种时间戳功能是否使我的 cookie 无效,即使据我所知它应该仍然有效?
最佳答案
在阅读了@uosel 的建议后,这让我走上了对这里到底发生了什么进行更深入分析的道路。而我的目标是只为 STS 本身而不是为 STS 使用站点创建一个持久性 cookie。这样,我始终可以在 STS 使用站点到期时在 STS 级别验证用户。
随着思路的不断深入,我突然意识到 STS 入门站点使用表单例份验证来保护 index.aspx 中出现的实际 WIF 授权。问题是我没有逻辑可以使用现有的表单例份验证票来处理到表单例份验证安全索引页面的传输。
这让我想到了一个类似的解决方案
if(User.Identity.IsAuthenticated)
{
if(IsValidUserCredentials())
{
var returnUrl = Request.QueryString["ReturnUrl"];
Response.Redirect(returnUrl ?? "default.aspx");
}
}
else
{
DisplayLoginForm()
}
关于c# - Windows Identity Foundation 安全 token 服务无法保持登录状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3585856/