Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

WSFederationAuthenticationModule.RedirectingToIdentityProvider Event

.NET Framework 4.6 and 4.5

Occurs when the module is going to redirect the user to the identity provider.

Namespace:  System.IdentityModel.Services
Assembly:  System.IdentityModel.Services (in System.IdentityModel.Services.dll)

'Declaration
Public Event RedirectingToIdentityProvider As EventHandler(Of RedirectingToIdentityProviderEventArgs)

You can access and modify the WS-Federation sign-in request through the RedirectingToIdentityProviderEventArgs.SignInRequestMessage property. For example, you can modify the BaseUri property in the sign-in message to change the identity provider to which the request will be redirected. The RedirectingToIdentityProvider event is a cancelable event and you can set the Cancel property to true to cancel the redirect.

The event is raised from inside the RedirectToIdentityProvider method through a call to the OnRedirectingToIdentityProvider method.

To handle this event in an ASP.NET application, create a method called WSFederationAuthentication_RedirectingToIdentityProvider in the global.asax file.

The following code shows how to add a handler for the RedirectingToIdentityProvider event in the Application_Init event in the global.asax file. The code is taken from the FederationForWebApps sample. For more information about this sample, see WIF Code Sample Index.

    void Application_Init()
    {
        // Code that runs on application init.
        FederatedAuthentication.WSFederationAuthenticationModule.RedirectingToIdentityProvider += new EventHandler<RedirectingToIdentityProviderEventArgs>(WSFederationAuthentication_RedirectingToIdentityProvider);
    }  

The following code shows the handler for the RedirectingToIdentityProvider event in the in the global.asax file of an RP. The code checks to see whether the incoming HTTP request contains a whr parameter, and, if it does, it sets this parameter on the WS-Federation sign-in request that will be sent to the STS. The code is taken from the FederationForWebApps sample. For more information about this sample, see WIF Code Sample Index.

The following code shows the handler for the RedirectingToIdentityProvider event in the in the global.asax file of a federation provider STS. The code checks to see whether the incoming HTTP request contains a whr parameter. If the request contains the whr parameter, the client is directed to the IP-STS for sign-in; if not, the client is directed to a home realm discovery page to select the IP-STS at which to sign in. The code is taken from the FederationForWebApps sample. For more information about this sample, see WIF Code Sample Index.

void WSFederationAuthentication_RedirectingToIdentityProvider(object sender, RedirectingToIdentityProviderEventArgs e)
{
    // Check if 'whr' parameter is specified.
    string identityProviderUri = HttpContext.Current.Request.QueryString["whr"];
    string action = HttpContext.Current.Request.QueryString["wa"];

    if (action == "wsignin1.0")
    {
        if (String.IsNullOrEmpty(identityProviderUri))
        {
            // Forward the user to the IdentityProvider selection page.
            identityProviderUri = "http://localhost:3000/FPSTS/homeRealmSelectionPage.aspx";
        }

        e.SignInRequestMessage.BaseUri = new Uri(identityProviderUri);
        e.SignInRequestMessage.Realm = "http://localhost:3000/FPSTS/Default.aspx";
        e.SignInRequestMessage.Context = HttpContext.Current.Request.QueryString.ToString();
    }
}

.NET Framework

Supported in: 4.6, 4.5
Show:
© 2015 Microsoft