Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7635105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:21:24+00:00 2026-05-31T07:21:24+00:00

I have searched (probed ,even) for an answer to this but haven’t come up

  • 0

I have searched (probed ,even) for an answer to this but haven’t come up with anything useful so far. I’m pretty new to ADFS, STS’s in general and WIF so please excuse any obvious ignorance or inappropriate use of terminology. 😉

I’m currently integrating a custom MVC3 app with an external IdP, via ADFS. The ADFS to IdP setup is all done and working.

Some parts of the site are accessible to anon users – in the web.config authentication mode has been set to none. The other parts are protected by having their controllers/action methods decorated by a custom System.Web.Mvc.AuthorizeAttribute.

All the usual modifications to the web.config for using the WsFederationAuthenticationModule have been made and it works 95%; the user can browse to the anon accessible parts of the site. When they try and hit the protected parts, the authorize attribute checks if they have some custom information from our IdP in the IClaimsPrincipals associated with the HttpContext.Current.User and then sets the ActionResult to 401 if not; The WsFederationAuthenticationModule kicks in and redirects them to the IdP’s login page. When they enter their details, they’re then successfully redirected with some FedAuth cookies and the authorization then passes.

The problem starts when they get to the IdP’s login page. This particular IdP has a link to return you directly to our site (to the same page the original request was made to), with this SAML response embedded somewhere (this is according to their documentation)

urn:oasis:names: tc:SAML:2.0:status: AuthnFailed

At this point, they are now “Unauthorized” and all the user will see (at least in dev) is a 401 page. You have to kill the session or otherwise get rid of that cookie to start again.

What I need to do is intercept that redirect request from the IdP, and essentially check for that particular SAML status, because the user should then be redirected to one of the unauthorized areas as if nothing has happened. I’ve tried something like this in the global.asax:

 protected void Application_Start()
    {
        // mvc stuff here....

        // add handler to intercept handling creation of security tokens by WsFederationAuthnticationModule
        FederatedAuthentication.ServiceConfigurationCreated += OnServiceConfigurationCreated;
    }

    void OnServiceConfigurationCreated(object sender, ServiceConfigurationCreatedEventArgs e)
    {
        FederatedAuthentication
            .WSFederationAuthenticationModule
            .SessionSecurityTokenCreated += WSFederationAuthenticationModule_SecuityTokenCreated;
    }

    public void WSFederationAuthenticationModule_SecuityTokenCreated (Object sender, SessionSecurityTokenCreatedEventArgs args) 
    {          
        var token = args.SessionToken;
        // do something with the session token here e.g. check for SAML status
    }

.. but I cant see anything useful on that token; nothing to indicate a specific response status. The fact that there is a FedAuth cookie at all but no custom info from the Idp is a dead give away that the user has been there but somehow failed to authenticate, but in principle I want to be able to see that status. I might have to deal with timeouts at the IdP as well….

Maybe I’m doing this all wrong, or just plain old don’t understand, but can somehow fill me in on how to determine those response statuses?

Phew. Thank you! 😀

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T07:21:26+00:00Added an answer on May 31, 2026 at 7:21 am

    Ok, so I’m going to answer my own question.

    The answer to whether I can get that custom status from my IdP is a no, at the moment. 🙁

    But this is only because ADFS is not setup to capture it and pass it on. Apparently you need to do some custom coding for capturing information from the back channel that is opened between ADFS and the IdP…. well beyond the current scope of work.

    As a work around for the moment:

    • If a request is made to the site and there is NO SAML token, its a new request by a user who has made no auth attempt at the Idp
    • If there is a SAML token but no ID from the IdP in the token (which is only present when they auth properly), then the user failed Auth for some reason
      • If there is a SAML token with the ID present, the user auth’d properly

    Not great but acceptable. BTW, all credit goes to YMC in this SO post for the following code which lets you check for SAML tokens:

    void WSFederationAuthenticationModule_SecurityTokenReceived(object sender, SecurityTokenReceivedEventArgs e)
        {
            var message = SignInResponseMessage.CreateFromFormPost(Request) as SignInResponseMessage;
            var rstr = new WSFederationSerializer()
                .CreateResponse(message,
                new WSTrustSerializationContext(
                    SecurityTokenHandlerCollectionManager.CreateDefaultSecurityTokenHandlerCollectionManager()));
        } 
    

    Pce!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have searched this question but didn't get / or understood the answer I
I have searched this but really I couldn't find the exact answer for .asmx
I have searched around for an answer to this but can't find one. When
I have searched google but it seems no one has come across this issue.
I have searched everywhere and can't find anything about this: I have a checkbox
I have searched for the answer to this and the reason I'm not finding
(have searched, but not been able to find a simple solution to this one
I have searched for an answer but am not finding it. I have 2
I have searched and I have received the same answer but I believe mine
I have searched high and low for a clue to or even the answer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.