У меня есть вызовы к API Членства и API Ролей в одной и той же области транзакции.Я читал, что открытие более одного соединения вызывает эскалацию, требующую включения распределенных транзакций, поэтому я ищу способ открыть одно соединение и поделиться им с: Членство, роли, мои собственные вызовы.
Вот рабочий код, который вызывает нежелательную эскалацию:
public static void InsertUser(string userName, string email, string roleName, int contactId, string comment)
{
/*
* Exceptions thrown here are caught in the DetailView's event handler and piped to the UI.
*/
using(var transactionScope = new TransactionScope(TransactionScopeOption.RequiresNew))
{
string password = Membership.GeneratePassword(Membership.MinRequiredPasswordLength, Membership.MinRequiredNonAlphanumericCharacters);
const string passwordQuestion = "Should you change your password question?";
const string passwordAnswer = "yes";
MembershipCreateStatus status;
MembershipUser user = Membership.CreateUser(userName, password, email, passwordQuestion, passwordAnswer, true, out status);
if(user == null)
{
throw new Exception(GetErrorMessage(status));
}
// Flesh out new user
user.Comment = comment;
Membership.UpdateUser(user);
// Give user a role
Roles.AddUserToRole(user.UserName, roleName);
// Create bridge table record
Guid userId = (Guid)ExceptionUtils.ThrowIfDefaultValue(user.ProviderUserKey, "ProviderUserkey is null!");
insertIntoAspnet_Users_To_Contact(userId, contactId);
// Send welcome email
EmailUtils.SendWelcomeEmailFromAdmin(userName, email, password, passwordQuestion, passwordAnswer, roleName);
transactionScope.Complete();
}
}
Спасибо