我在Web应用程序中使用ASP.NET成员身份。 我在usercontrol中有以下代码:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="memberRegister.ascx.cs" Inherits="UmbracoMembership.usercontrols.memberRegister" %>
<asp:LoginView ID="lvRegister" runat="server">
<AnonymousTemplate>
<asp:CreateUserWizard ID="cwMember" runat="server"
LoginCreatedUser="False" DisableCreatedUser="True"
OnCreatedUser="cwMember_CreatedUser" ContinueDestinationPageUrl="~/Umbraco/">
<WizardSteps>
<asp:CreateUserWizardStep ID="cuwStep1" runat="server">
<ContentTemplate>
<div class="row1"><label>Username:</label><asp:TextBox ID="Username" runat="server" CssClass="inner-field"></asp:TextBox></div>
<div class="row1"><label>Full Name:</label><asp:TextBox ID="FullName" runat="server" CssClass="inner-field"></asp:TextBox></div>
<div class="row1"><label>Email:</label><asp:TextBox ID="Email" runat="server" CssClass="inner-field"></asp:TextBox></div>
<div class="row1"><label>Password:</label><asp:TextBox ID="Password" runat="server" TextMode="Password" CssClass="inner-field"></asp:TextBox></div>
<div class="row1"><label>Confirm Password:</label><asp:TextBox ID="ConfirmPassword" runat="server" TextMode="Password" CssClass="inner-field"></asp:TextBox></div>
</ContentTemplate>
<CustomNavigationTemplate>
<div class="button-area">
<asp:Button ID="CreateUserButton" runat="server" Text="" CommandName="MoveNext" ValidationGroup="CreateUserWizard" CssClass="create-button"/>
</div>
</CustomNavigationTemplate>
</asp:CreateUserWizardStep>
<asp:CompleteWizardStep ID="cuwStep2" runat="server">
<ContentTemplate>
<div>Your account has been created, but still needs to be activated. <br />You will be recieving an activation email soon.</div>
</ContentTemplate>
</asp:CompleteWizardStep>
</WizardSteps>
</asp:CreateUserWizard>
</AnonymousTemplate>
</asp:LoginView>
这就是代码隐藏:
public partial class memberRegister : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
// is user is already logged on, redirect to home page (doesn't make sense to register when already logged in...)
if (umbraco.library.IsLoggedOn())
Response.Redirect("~/");
}
protected void cwMember_CreatedUser(object sender, EventArgs e)
{
CreateUserWizard cuw = (CreateUserWizard)sender;
MembershipUser user = System.Web.Security.Membership.GetUser(cuw.UserName);
if (user != null)
{
//create a new GUID
string newUserGUID = System.Guid.NewGuid().ToString("N");
//get profile for this user.
UmbracoMembership.MemberProfile mp = MemberProfile.GetUserProfile(cuw.UserName);
mp.AuthGuid = newUserGUID;
mp.fullName = ((TextBox)cuw.CreateUserStep.ContentTemplateContainer.FindControl("FullName")).Text;
mp.email = ((TextBox)cuw.CreateUserStep.ContentTemplateContainer.FindControl("Email")).Text;
mp.Save();
//add user to the site members group
Roles.AddUserToRole(cuw.UserName, "RegisteredUsers");
//Send email
String fromAddress = "eample@bla.com";
String toAddress = mp.email;
SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
smtp.EnableSsl = true;
smtp.Credentials = new NetworkCredential("eample@bla.com", "1234");
MailAddress _from = new MailAddress(fromAddress);
MailAddress _to = new MailAddress(toAddress);
MailMessage mMsg = new MailMessage(_from, _to);
mMsg.Subject = "Welcome!";
mMsg.Body = "Please click the following link to authorize your new account. " + "http://" + Request.ServerVariables["HTTP_HOST"] + Request.ApplicationPath.TrimEnd('/') + "/auth.aspx?a=" + user.UserName + "&b=" + newUserGUID;
smtp.Send(mMsg);
}
}
}
}
出于某种原因,在单击“创建用户”并发生回发后,用户将返回到注册页面而不是转到完整页面。 我尝试了一切。现在半天都在玩各种各样的设置。 有什么想法吗?
答案 0 :(得分:0)
嗯......事实证明,如果你在CreateUserWizard中没有“处理”异常,那么什么都没发生。创建用户并且不显示代码隐藏错误。
我刚刚添加了一个try ... catch和response.write(ex.message)
,这给了我错误。
错误本身是概要文件管理器的问题。
似乎网上的大多数示例都是在asp.net 2.0中为Profile Provider制作的。在asp.net 4中,如果您自己实现ProfileBase类并在那里定义属性,则无需在web.config配置文件属性中定义。