如何在app域之间传递经过身份验证的会话

Rya*_*ter 9 c# membership asp.net asp.net-membership

假设您有网站www.xyz.com和www.abc.com.

假设用户访问www.abc.com并通过普通的ASP .NET成员资格提供程序进行身份验证.

然后,从该网站,他们被发送到(重定向,链接,无论什么工作)网站www.xyz.com,网站www.abc.com的意图是将该用户传递到另一个网站作为isAuthenticated的状态,这样网站www.xyz.com就不再要求所述用户的凭证.

这需要什么才能发挥作用?我对此有一些限制,用户数据库是完全独立的,它不是组织内部的,在所有方面,它就像从stackoverflow.com传递到google一样经过身份验证,它本质上是独立的.链接到相关文章就足够了.

cra*_*ver 5

尝试通过设置web.config身份验证部分来使用FormAuthentication,如下所示:

<authentication mode="Forms">
  <forms name=".ASPXAUTH" requireSSL="true" 
      protection="All" 
      enableCrossAppRedirects="true" />
</authentication>
Run Code Online (Sandbox Code Playgroud)

生成机器密钥.示例:生成MachineKey的最简单方法 - 提示和技巧:ASP.NET,IIS ...

发布到其他应用程序时,身份验证票证将作为隐藏字段传递.在从第一个应用程序阅读帖子时,第二个应用程序将读取加密的票证并对用户进行身份验证.以下是传递该字段的页面示例:

的.aspx:

<form id="form1" runat="server">
  <div>
    <p><asp:Button ID="btnTransfer" runat="server" Text="Go" PostBackUrl="http://otherapp/" /></p>
    <input id="hdnStreetCred" runat="server" type="hidden" />
  </div>
</form>
Run Code Online (Sandbox Code Playgroud)

后台代码:

protected void Page_Load(object sender, EventArgs e)
{
    FormsIdentity cIdentity = Page.User.Identity as FormsIdentity;
    if (cIdentity != null)
    {
        this.hdnStreetCred.ID = FormsAuthentication.FormsCookieName;
        this.hdnStreetCred.Value = FormsAuthentication.Encrypt(((FormsIdentity)User.Identity).Ticket);
    }
}
Run Code Online (Sandbox Code Playgroud)

另请参阅Wrox 本书第5章中的跨应用程序表单身份验证部分.除了提供自制SSO解决方案之外,它还推荐上述答案.