I need some sample code to integrate ADFS login in my asp.net web form application. Already ADFS is setup on my server and meta data link is available with us.
What I have tried:
I have created a sample webforms application with below code in startup.cs:
private static string adfsRealm = ConfigurationManager.AppSettings["ida:Wtrealm"];
private static string adfsMetadata = ConfigurationManager.AppSettings["ida:ADFSMetadata"];
private static string adfsWreply = ConfigurationManager.AppSettings["ida:Wreply"];
public void Configuration(IAppBuilder app)
{
app.Properties["Microsoft.Owin.Security.Constants.DefaultSignInAsAuthenticationType"] = "ExternalCookie";
app.UseCookieAuthentication(new Microsoft.Owin.Security.Cookies.CookieAuthenticationOptions
{
AuthenticationType = "ExternalCookie",
AuthenticationMode = Microsoft.Owin.Security.AuthenticationMode.Passive
});
var testADFS = new WsFederationAuthenticationOptions
{
MetadataAddress = adfsMetadata,
Wreply = adfsWreply,
Wtrealm = adfsRealm
};
app.UseWsFederationAuthentication(testADFS);
}
and below code in default.aspx:
if (!Request.IsAuthenticated)
{
HttpContext.Current.GetOwinContext().Authentication.Challenge(new AuthenticationProperties { RedirectUri = "~/" },
WsFederationAuthenticationDefaults.AuthenticationType);
}
when I run the application it is redirecting to the login page with below error, Please let me know what might be the issue.:
An error occurred
An error occurred. Contact your administrator for more information.
Error details
Activity ID: a1f3f98b-4d35-4cf9-4600-00800100003a
Error time: Wed, 11 Sep 2019 05:50:48 GMT
Cookie: enabled
User agent string: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36