我们正在尝试使用ASP.NET MVC构建跨域单点登录解决方案。
是否有现有的解决方案或教程可用?
是否有现有的解决方案或教程可用?
如果您的 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));
}
}
在本地应用程序中,您需要启用无 cookie 的表单验证,并通过设置 enableCrossAppRedirect 允许来自外部应用程序的已验证用户。
<authentication mode="Forms">
<forms enableCrossAppRedirect="true" cookieless="useUri" />
</authentication>
注:
另请参见 FormsAuthentication.RedirectFromLoginPage - http://msdn.microsoft.com/en-us/library/ka5ffkce.aspx。
在我的情况下,ReturnUrl 丢失了 URL 的域部分 :(