diff options
Diffstat (limited to 'samples/OpenIdProviderWebForms/Default.aspx.cs')
-rw-r--r-- | samples/OpenIdProviderWebForms/Default.aspx.cs | 46 |
1 files changed, 29 insertions, 17 deletions
diff --git a/samples/OpenIdProviderWebForms/Default.aspx.cs b/samples/OpenIdProviderWebForms/Default.aspx.cs index 4843639..5d27251 100644 --- a/samples/OpenIdProviderWebForms/Default.aspx.cs +++ b/samples/OpenIdProviderWebForms/Default.aspx.cs @@ -1,6 +1,8 @@ namespace OpenIdProviderWebForms { using System; + using System.Threading.Tasks; using System.Web.Security; + using System.Web.UI; using System.Web.UI.WebControls; using DotNetOpenAuth.Messaging; using DotNetOpenAuth.OpenId; @@ -12,32 +14,42 @@ /// </summary> public partial class _default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { - if (Request.QueryString["rp"] != null) { - if (Page.User.Identity.IsAuthenticated) { - this.SendAssertion(Request.QueryString["rp"]); - } else { - FormsAuthentication.RedirectToLoginPage(); - } - } else { - TextBox relyingPartySite = (TextBox)this.loginView.FindControl("relyingPartySite"); - if (relyingPartySite != null) { - relyingPartySite.Focus(); - } - } + this.RegisterAsyncTask( + new PageAsyncTask( + async ct => { + if (Request.QueryString["rp"] != null) { + if (Page.User.Identity.IsAuthenticated) { + await this.SendAssertionAsync(Request.QueryString["rp"]); + } else { + FormsAuthentication.RedirectToLoginPage(); + } + } else { + TextBox relyingPartySite = (TextBox)this.loginView.FindControl("relyingPartySite"); + if (relyingPartySite != null) { + relyingPartySite.Focus(); + } + } + })); } - protected void sendAssertionButton_Click(object sender, EventArgs e) { - TextBox relyingPartySite = (TextBox)this.loginView.FindControl("relyingPartySite"); - this.SendAssertion(relyingPartySite.Text); + protected async void sendAssertionButton_Click(object sender, EventArgs e) { + this.RegisterAsyncTask( + new PageAsyncTask( + async ct => { + TextBox relyingPartySite = (TextBox)this.loginView.FindControl("relyingPartySite"); + await this.SendAssertionAsync(relyingPartySite.Text); + })); } - private void SendAssertion(string relyingPartyRealm) { + private async Task SendAssertionAsync(string relyingPartyRealm) { Uri providerEndpoint = new Uri(Request.Url, Page.ResolveUrl("~/server.aspx")); OpenIdProvider op = new OpenIdProvider(); try { // Send user input through identifier parser so we accept more free-form input. string rpSite = Identifier.Parse(relyingPartyRealm); - op.PrepareUnsolicitedAssertion(providerEndpoint, rpSite, Util.BuildIdentityUrl(), Util.BuildIdentityUrl()).Send(); + var response = await op.PrepareUnsolicitedAssertionAsync(providerEndpoint, rpSite, Util.BuildIdentityUrl(), Util.BuildIdentityUrl()); + await response.SendAsync(); + this.Context.Response.End(); } catch (ProtocolException ex) { Label errorLabel = (Label)this.loginView.FindControl("errorLabel"); errorLabel.Visible = true; |