单点登录ASP.NET MVC

Mik*_*ike 8 asp.net-mvc jquery xmlhttprequest single-sign-on

我们正在尝试使用ASP.NET MVC构建跨域单点登录解决方案.

是否有现有的解决方案或教程?

AJ.*_*AJ. 10

如果Web应用程序位于同一服务器同一域中,那么您需要做的就是确保Web配置(machineKey)中的Validationkey和加密密钥相同.

在您的示例中,您需要将身份验证票证附加到查询字符串,以将其传输回其他域,例如:

public void Login(string userName, string password)
{
    if(AuthenticateUser(userName,password))
    {
        Response.Redirect(String.format("{0}?{1}={2}"), 
            Request.QueryString["ReturnUrl"],
            FormsAuthentication.FormsCookieName,
            FormsAuthentication.GetAuthCookie(userName, false).Value));
    }
}
Run Code Online (Sandbox Code Playgroud)

在本地应用程序上,您必须启用无cookie表单身份验证,并通过设置enableCrossAppRedirect允许经过身份验证的用户来自外部应用程序.

<authentication mode="Forms">
    <forms enableCrossAppRedirect="true" cookieless="useUri" />
</authentication>
Run Code Online (Sandbox Code Playgroud)

笔记:

  1. 另请参见FormsAuthentication.RedirectFromLoginPage - http://msdn.microsoft.com/en-us/library/ka5ffkce.aspx.

  2. 在我的情况下ReturnUrl丢失了url的域名部分:(