[英]Integrating ADFS SSO into existing .net web application
I have the active directory set up correctly and i can go to the IDP sign on page with a URL that looks like this:我的活动目录设置正确,我可以使用如下所示的 URL 转到 IDP 登录页面:
https://SERVER/adfs/ls/idpinitiatedsignon.htm
I created a new project and am able to do a simple sign on through that app.我创建了一个新项目,并且能够通过该应用程序进行简单的登录。
Now i am trying to implement that into a current web application code.现在我正在尝试将其实现到当前的 Web 应用程序代码中。
In the simple project, after the below code runs, it redirects to the IDP sign on page.在简单的项目中,下面的代码运行后,它会重定向到 IDP 登录页面。
public class Startup
{
public void Configuration(IAppBuilder app)
{
ConfigureAuth(app);
}
private static string realm = ConfigurationManager.AppSettings["ida:Wtrealm"];
private static string adfsMetadata = ConfigurationManager.AppSettings["ida:ADFSMetadata"];
public void ConfigureAuth(IAppBuilder app)
{
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions());
app.UseWsFederationAuthentication(
new WsFederationAuthenticationOptions
{
Wtrealm = realm,
MetadataAddress = adfsMetadata
});
}
}
When this code runs in the existing project, it never redirects and instead goes ahead and loads the Default.aspx page.当此代码在现有项目中运行时,它永远不会重定向,而是继续加载 Default.aspx 页面。 Am i missing something?
我错过了什么吗? I want the user to sign in if they aren't already, but i can't figure out why the application is not redirecting to log in. Any help would be much appreciated.
如果用户还没有登录,我希望用户登录,但我无法弄清楚为什么应用程序没有重定向到登录。任何帮助将不胜感激。
I found a solution after a couple days of trying.经过几天的尝试,我找到了解决方案。 I added this code to the top of the Default.aspx page_load method to run this if not signed in:
我将此代码添加到 Default.aspx page_load 方法的顶部以在未登录时运行此代码:
if (!System.Web.HttpContext.Current.Request.IsAuthenticated)
{
System.Web.HttpContext.Current.GetOwinContext().Authentication.Challenge(new AuthenticationProperties { RedirectUri = "/" },
WsFederationAuthenticationDefaults.AuthenticationType);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.