Export (0) Print
Expand All

WSFederationAuthenticationModule::RedirectingToIdentityProvider Event

.NET Framework 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)

public:
 event EventHandler<RedirectingToIdentityProviderEventArgs^>^ RedirectingToIdentityProvider {
	void add (EventHandler<RedirectingToIdentityProviderEventArgs^>^ value);
	void remove (EventHandler<RedirectingToIdentityProviderEventArgs^>^ value);
}

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.5.2, 4.5.1, 4.5

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft