protected void Page_Load()
        {
            string action = Request.QueryString[WSFederationConstants.Parameters.Action];

            try
            {
                if (action == WSFederationConstants.Actions.SignIn)
                {
                    // Process signin request.
                    if (SimulatedWindowsAuthenticationOperations.TryToAuthenticateUser(this.Context, this.Request, this.Response))
                    {
                        SecurityTokenService  sts             = new IdentityProviderSecurityTokenService(IdentityProviderSecurityTokenServiceConfiguration.Current);
                        SignInRequestMessage  requestMessage  = (SignInRequestMessage)WSFederationMessage.CreateFromUri(Request.Url);
                        SignInResponseMessage responseMessage = FederatedPassiveSecurityTokenServiceOperations.ProcessSignInRequest(requestMessage, User, sts);
                        FederatedPassiveSecurityTokenServiceOperations.ProcessSignInResponse(responseMessage, this.Response);
                    }
                }
                else if (action == WSFederationConstants.Actions.SignOut)
                {
                    // Process signout request in the default page.
                    this.Response.Redirect("~/?" + Request.QueryString, false);
                }
                else
                {
                    throw new InvalidOperationException(
                              string.Format(
                                  CultureInfo.InvariantCulture,
                                  "The action '{0}' (Request.QueryString['{1}']) is unexpected. Expected actions are: '{2}' or '{3}'.",
                                  string.IsNullOrEmpty(action) ? "<EMPTY>" : action,
                                  WSFederationConstants.Parameters.Action,
                                  WSFederationConstants.Actions.SignIn,
                                  WSFederationConstants.Actions.SignOut));
                }
            }
            catch (Exception exception)
            {
                throw new Exception("An unexpected error occurred when processing the request. See inner exception for details.", exception);
            }
        }
Beispiel #2
0
        protected override void OnPreRender(EventArgs e)
        {
            string action = Request.QueryString[WSFederationConstants.Parameters.Action];

            try
            {
                if (action == WSFederationConstants.Actions.SignIn)
                {
                    // Process signin request.
                    string endpointAddress = "~/SimulatedWindowsAuthentication.aspx";
                    this.Response.Redirect(endpointAddress + "?" + Request.QueryString, false);
                }
                else if (action == WSFederationConstants.Actions.SignOut)
                {
                    // Process signout request.
                    SimulatedWindowsAuthenticationOperations.LogOutUser(this.Request, this.Response);
                    SignOutRequestMessage requestMessage = (SignOutRequestMessage)WSFederationMessage.CreateFromUri(Request.Url);
                    FederatedPassiveSecurityTokenServiceOperations.ProcessSignOutRequest(requestMessage, this.User, null, this.Response);
                    this.ActionExplanationLabel.Text = "Sign out from the issuer has been requested.";
                }
                else
                {
                    throw new InvalidOperationException(
                              string.Format(
                                  CultureInfo.InvariantCulture,
                                  "The action '{0}' (Request.QueryString['{1}']) is unexpected. Expected actions are: '{2}' or '{3}'.",
                                  string.IsNullOrEmpty(action) ? "<EMPTY>" : action,
                                  WSFederationConstants.Parameters.Action,
                                  WSFederationConstants.Actions.SignIn,
                                  WSFederationConstants.Actions.SignOut));
                }
            }
            catch (Exception exception)
            {
                throw new Exception("An unexpected error occurred when processing the request. See inner exception for details.", exception);
            }
        }
 protected void ContinueButtonClick(object sender, EventArgs e)
 {
     SimulatedWindowsAuthenticationOperations.LogOnUser(this.UserList.SelectedValue, this.Context, this.Request, this.Response);
     this.HandleSignInRequest();
 }