ASP.net重定向用户的条件

时间:2010-10-19 11:42:16

标签: c# asp.net redirect asp.net-membership

鉴于我的注册页面:

            <asp:CompleteWizardStep ID="CompleteWizardStep1" runat="server">
                <ContentTemplate>

                    <span class="defHead">Thank You!</span><br /><br />
                    You are now registered on our system.<br /><br />

                </ContentTemplate>
            </asp:CompleteWizardStep>

   </WizardSteps>

<CreateUserButtonStyle CssClass="searchBtn" Width="120" Height="26" />
<ContinueButtonStyle CssClass="searchBtn" Width="120" Height="26" />

如果满足条件,我想重定向用户,并且它们处于上述步骤。我试过了:

protected void Page_Load(object sender, EventArgs e)
        {
            if (CompleteWizardStep1.Visible)
            {
                Response.Redirect("viewBasket.aspx?action=news");
            }

但没有运气!似乎找不到任何东西。

1 个答案:

答案 0 :(得分:1)

发现它:))

在创建用户向导控件上添加对函数OnCreatedUser的引用:

<asp:CreateUserWizard
        id="CreateUserWizard1"
        Runat="server"
        OnCreatedUser="CreatedUser"

然后在代码中定义您希望运行的功能:

protected void CreatedUser(object sender, EventArgs e)
  {
      Response.Redirect("viewBasket.aspx?action=news");
  }

请注意,这将阻止用户登录其帐户。保持用户登录:

    protected void CreatedUser(object sender, EventArgs e)
      {
                TextBox userNameTextBox = (TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("UserName");
                MembershipUser user = Membership.GetUser(userNameTextBox.Text);
                FormsAuthentication.SetAuthCookie(userNameTextBox.Text, false);
                Response.Redirect("viewBasket.aspx?action=news");
      }