Click here to Skip to main content
14,300,474 members
Rate this:
Please Sign up or sign in to vote.
See more:
I need some sample code to integrate ADFS login in my 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
            //add to pipeline

and below code in default.aspx:
if (!Request.IsAuthenticated)


              HttpContext.Current.GetOwinContext().Authentication.Challenge(new AuthenticationProperties { RedirectUri = "~/" },


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
Updated 11-Sep-19 20:24pm
Dominic Burford 15-May-19 6:18am
What code have you tried? Are you getting an error? There are plenty of ADFS examples on the net. Use one of these to get started, and when you get stuck post a more specific question.
wajans 15-May-19 6:36am
I searched a lot online but didn't find any code for ADFS for Web forms. Could you please guide me or share any link.
phil.o 15-May-19 7:30am
The second link in your question (the one which you modified) explains the authentication process through ADFS. Please show how you tried to integrate it in your solution (of which we have no knowledge about). There does not exist a ready-made, universal solution for this, you will not find some code to copy-paste which will magically adapt to your project.

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Here's a couple I found while searching for ADFS.

ADFS Step-by-Step Example - wcf pandu[^]

Claims-Aware Applications | Microsoft Docs[^]
wajans yesterday
Hi Dominic,
There was a problem in the configuration. I fixed it now. Any request coming to my application is being redirected to the adfs login, but once login its redirected back to the default.aspx page and giving this error: "HTTP Error 405.0 - Method Not Allowed".

I update code in default.aspx, instead of "~/" in redirecturi mentioned in the question, I added redirecturi="default.aspx".

what might be wrong in the code? Please help.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100