사용자 정의 MembershipProvider와 함께 CreateUserWizard를 사용하여 데이터베이스에 사용자를 추가하고 있습니다. 현재 사용자가 데이터베이스에 성공적으로 추가되었으며 CreatedUser 이벤트를 사용하여 양식에 캡처 된 추가 정보를 저장하고 있습니다. 이것은 잘 작동합니다. 그러나 업데이트 도중 어떤 오류 조건도 처리 할 수 있기를 원합니다.CreatedUser 이벤트에서 CreateUserWizard 취소
추가 정보 업데이트가 실패하면 오류가있는 CreateUserWizard 양식을 다시 표시하는 방법이 있습니까? 사전에
protected void RegisterUserWizard_CreatedUser(object sender, EventArgs e)
{
try
{
// Try to update the customer table with the additional information
using (OrderEntities entities = new OrderEntities())
{
// Read in all the values from the form
TextBox custTitle = (TextBox)RegisterUserWizard.CreateUserStep.ContentTemplateContainer.FindControl("CustomerTitle");
TextBox custName = (TextBox)RegisterUserWizard.CreateUserStep.ContentTemplateContainer.FindControl("CustomerName");
TextBox custSurname = (TextBox)RegisterUserWizard.CreateUserStep.ContentTemplateContainer.FindControl("CustomerSurname");
TextBox custAddress1 = (TextBox)RegisterUserWizard.CreateUserStep.ContentTemplateContainer.FindControl("CustomerAddressLine1");
TextBox custAddress2 = (TextBox)RegisterUserWizard.CreateUserStep.ContentTemplateContainer.FindControl("CustomerAddressLine2");
TextBox custAddress3 = (TextBox)RegisterUserWizard.CreateUserStep.ContentTemplateContainer.FindControl("CustomerAddressLine3");
TextBox custCity = (TextBox)RegisterUserWizard.CreateUserStep.ContentTemplateContainer.FindControl("CustomerCity");
TextBox custCounty = (TextBox)RegisterUserWizard.CreateUserStep.ContentTemplateContainer.FindControl("CustomerCounty");
TextBox custPostcode = (TextBox)RegisterUserWizard.CreateUserStep.ContentTemplateContainer.FindControl("CustomerPostcode");
DropDownList custCountry = (DropDownList)RegisterUserWizard.CreateUserStep.ContentTemplateContainer.FindControl("CustomerCountry");
Customer custInfo = entities.Customers.Where(c => c.UserName == RegisterUserWizard.UserName).FirstOrDefault();
if (custInfo != null)
{
custInfo.Email = RegisterUserWizard.Email;
custInfo.Password = RegisterUserWizard.Password;
custInfo.Title = custTitle.Text;
custInfo.Firstname = custName.Text;
custInfo.Surname = custSurname.Text;
custInfo.AddressLine1 = custAddress1.Text;
custInfo.AddressLine2 = custAddress2.Text;
custInfo.AddressLine3 = custAddress3.Text;
custInfo.City = custCity.Text;
custInfo.County = custCounty.Text;
custInfo.Postcode = custPostcode.Text;
custInfo.CountryID = custCountry.SelectedValue;
custInfo.CreatedDate = DateTime.Now;
entities.SaveChanges();
FormsAuthentication.SetAuthCookie(RegisterUserWizard.UserName, false);
// Redirect user back to calling page
string continueUrl = RegisterUserWizard.ContinueDestinationPageUrl;
if (String.IsNullOrEmpty(continueUrl))
{
continueUrl = "~/";
}
Response.Redirect(continueUrl);
}
else
{
// Redisplay CreateUserWizard showing error message
}
}
}
catch
{
// Redisplay CreateUserWizard showing error message
}
}
많은 감사는 콘텐츠 템플릿을 사용하여 ID ErrorMessage가와 리터럴 컨트롤을 추가 할 경우
감사합니다. Juan, 콘텐츠 템플릿에 이미 정의 된 ErrorMessage라는 리터럴이 있으며 예상대로 사용자 생성시 사용자 지정 MembershipProvider에서 발생한 오류를 표시합니다. 내가 가진 문제는 CreatedUser 이벤트 내에서 보조 테이블을 업데이트하려고 할 때입니다. – oliver