James James

James James

  • NA
  • 9
  • 2.7k

Amazon Cognito and ASP.NET C# Integration

Nov 17 2020 2:09 AM
Hello, I am trying to implement cognito user pool into my login, register and logout and I have tried this code for Signup
  1. protected void Button1_Click(object sender, EventArgs e)    
  2. {    
  3.    AddCognitoUser();    
  4. }    
  5. static async Task AddCognitoUser()    
  6. {    
  7.    string username = "Name";    
  8.    string password = "Password";    
  9.    string phonenumber = "+678172932";    
  10.    string email = "[email protected]";    
  11.    AmazonCognitoIdentityProviderClient provider =    
  12.       new AmazonCognitoIdentityProviderClient(new Amazon.Runtime.AnonymousAWSCredentials());    
  13.    SignUpRequest signUpRequest = new SignUpRequest();    
  14.    signUpRequest.ClientId = "clientid";    
  15.    signUpRequest.Username = username;    
  16.    signUpRequest.Password = password;    
  17.   
  18.    AttributeType attributeType = new AttributeType();    
  19.    attributeType.Name = "phone_number";    
  20.    attributeType.Value = phonenumber;    
  21.    signUpRequest.UserAttributes.Add(attributeType);    
  22.   
  23.    AttributeType attributeType1 = new AttributeType();    
  24.    attributeType1.Name = "email";    
  25.    attributeType1.Value = email;    
  26.    signUpRequest.UserAttributes.Add(attributeType1);    
  27.   
  28.    try    
  29.    {    
  30.       SignUpResponse result = await provider.SignUpAsync(signUpRequest);    
  31.    }    
  32.    catch (Exception e)    
  33.    {    
  34.       System.Diagnostics.Debug.WriteLine(e);    
  35.    }    
  36. }  
When i run these codes, there is an error saying "An unhandled exception of type 'System.NullReferenceException' occurred in mscorlib.dll" and i tried to find but there is nothing null in the codes. Is there anything that i do wrong?
 
Or is there any other better tutorial that help to integrate cognito with asp.net c#?
 
Any help will be really helpful.
Thank You.

Answers (2)