我在 Asp.Net Membership 中创建了一个自定义 CreateUser。现在我想要的是在创建用户时它应该被重定向为 default.aspx 页面上的登录用户。我如何验证并重定向到默认页面。我不希望他再次登录,但是当用户成功创建时,它应该自动登录并转到默认页面。
这是我的代码。
public string AddUser(string UserName, string FirstName, string LastName, string Gender, string EmailID, string Password, string Mobile, string SecurityQuestion, string SecurityAnswer)
{
MembershipCreateStatus CreateStatus;
MembershipUser newUser = Membership.CreateUser(UserName, Password, EmailID, SecurityQuestion, SecurityAnswer, true, out CreateStatus);
if (CreateStatus == MembershipCreateStatus.Success)
{
Guid newUserId = (Guid)newUser.ProviderUserKey;
if (RegisterCustomFields(newUserId, FirstName, LastName, Gender, Mobile) != 0)
{
Roles.AddUserToRole(newUser.UserName, "User");
ReturnMsg = "Successfully Created ";
}
else
{
Membership.DeleteUser(newUser.UserName);
ReturnMsg = "Error Creating User";
}
}
else
{
switch (CreateStatus)
{
case MembershipCreateStatus.DuplicateUserName:
ReturnMsg = "There already exists a user with this username.";
break;
case MembershipCreateStatus.DuplicateEmail:
ReturnMsg = "There already exists a user with this email address.";
break;
case MembershipCreateStatus.InvalidEmail:
ReturnMsg = "There email address you provided in invalid.";
break;
case MembershipCreateStatus.InvalidAnswer:
ReturnMsg = "There security answer was invalid.";
break;
case MembershipCreateStatus.InvalidPassword:
ReturnMsg = "The password you provided is invalid. It must be seven characters long and have at least one non-alphanumeric character.";
break;
default:
ReturnMsg = "There was an unknown error; the user account was NOT created.";
break;
}
}
return ReturnMsg;
}