User login after registration

how to automatically log in after creating an account

using asp.net 3.5 and authentication

here is the code:

<asp:CreateUserWizard ID="mainSignUp" runat="server" CreateUserButtonText="SignUp" FinishDestinationPageUrl="copyPastPage.aspx" ContinueDestinationPageUrl="~/copyPastPage.aspx" OnCreatedUser="redirect" LoginCreatedUser="true"> <CreateUserButtonStyle CssClass="signUpButton" /> <TextBoxStyle BorderStyle="None" Height="35px" Width="200px" /> <WizardSteps> <asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server" > <ContentTemplate> <table> <tr> <td align="right"> <asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">User Name:</asp:Label> </td> <td> <asp:TextBox ID="UserName" runat="server" BorderStyle="None" BorderWidth="1px" CssClass="signUpTextBox" Height="39px" Width="197px"></asp:TextBox> <asp:RequiredFieldValidator ID="UserNameRequired" runat="server" ControlToValidate="UserName" ErrorMessage="User Name is required." ToolTip="User Name is required." ValidationGroup="mainSignUp">*</asp:RequiredFieldValidator> </td> </tr> <tr> <td align="right"> <asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">Password:</asp:Label> </td> <td> <asp:TextBox ID="Password" runat="server" BorderStyle="None" BorderWidth="1px" CssClass="signUpTextBox" Height="39px" TextMode="Password" Width="197px"></asp:TextBox> <asp:RequiredFieldValidator ID="PasswordRequired" runat="server" ControlToValidate="Password" ErrorMessage="Password is required." ToolTip="Password is required." ValidationGroup="mainSignUp">*</asp:RequiredFieldValidator> </td> </tr> <tr> <td align="right"> <asp:Label ID="ConfirmPasswordLabel" runat="server" AssociatedControlID="ConfirmPassword">Confirm Password:</asp:Label> </td> <td> <asp:TextBox ID="ConfirmPassword" runat="server" BorderStyle="None" BorderWidth="1px" CssClass="signUpTextBox" Height="39px" TextMode="Password" Width="197px"></asp:TextBox> <asp:RequiredFieldValidator ID="ConfirmPasswordRequired" runat="server" ControlToValidate="ConfirmPassword" ErrorMessage="Confirm Password is required." ToolTip="Confirm Password is required." ValidationGroup="mainSignUp">*</asp:RequiredFieldValidator> </td> </tr> <tr> <td align="right"> <asp:Label ID="EmailLabel" runat="server" AssociatedControlID="Email">E-mail:</asp:Label> </td> <td> <asp:TextBox ID="Email" runat="server" BorderStyle="None" BorderWidth="1px" CssClass="signUpTextBox" Height="39px" Width="197px"></asp:TextBox> <asp:RequiredFieldValidator ID="EmailRequired" runat="server" ControlToValidate="Email" ErrorMessage="E-mail is required." ToolTip="E-mail is required." ValidationGroup="mainSignUp">*</asp:RequiredFieldValidator> </td> </tr> <tr> <td align="right"> <asp:Label ID="QuestionLabel" runat="server" AssociatedControlID="Question">Security Question:</asp:Label> </td> <td> <asp:TextBox ID="Question" runat="server" BorderStyle="None" BorderWidth="1px" CssClass="signUpTextBox" Height="39px" Width="197px"></asp:TextBox> <asp:RequiredFieldValidator ID="QuestionRequired" runat="server" ControlToValidate="Question" ErrorMessage="Security question is required." ToolTip="Security question is required." ValidationGroup="mainSignUp">*</asp:RequiredFieldValidator> </td> </tr> <tr> <td align="right"> <asp:Label ID="AnswerLabel" runat="server" AssociatedControlID="Answer">Security Answer:</asp:Label> </td> <td> <asp:TextBox ID="Answer" runat="server" BorderStyle="None" BorderWidth="1px" CssClass="signUpTextBox" Height="39px" Width="197px"></asp:TextBox> <asp:RequiredFieldValidator ID="AnswerRequired" runat="server" ControlToValidate="Answer" ErrorMessage="Security answer is required." ToolTip="Security answer is required." ValidationGroup="mainSignUp">*</asp:RequiredFieldValidator> </td> </tr> <tr> <td align="center" colspan="2"> <asp:CompareValidator ID="PasswordCompare" runat="server" ControlToCompare="Password" ControlToValidate="ConfirmPassword" Display="Dynamic" ErrorMessage="The Password and Confirmation Password must match." ValidationGroup="mainSignUp"></asp:CompareValidator> </td> </tr> <tr> <td align="center" colspan="2" style="color:Red;"> <asp:Literal ID="ErrorMessage" runat="server" EnableViewState="False"></asp:Literal> </td> </tr> </table> </ContentTemplate> </asp:CreateUserWizardStep> <asp:CompleteWizardStep ID="CompleteWizardStep1" runat="server" /> </WizardSteps> </asp:CreateUserWizard> 

and the code behind:

 public partial class Default3 : System.Web.UI.Page 

{protected void Page_Load (object sender, EventArgs e) {}

 protected void redirect(object sender, EventArgs e) { FormsAuthentication.SetAuthCookie(USER_NAME, true); Response.Redirect("copyPastPage.aspx"); } 

}

early

+2
source share
3 answers
 FormsAuthentication.RedirectFromLoginPage(mainSignUp.UserName, true); 

Put the above line inside the redirect method and delete these two lines and let us know if this helps

+1
source

After successful registration, simply use this line:

 FormsAuthentication.SetAuthCookie(USER_NAME, true); 

the true at the end means (from official documentation):

true to create a persistent cookie (which is stored in browser sessions); otherwise false.

0
source

If you use the CreateUserWizard control to register a user, you can set the LoginCreatedUser property to true to automatically log in after registration is completed.

0
source

Source: https://habr.com/ru/post/1347697/


All Articles