Click here to Skip to main content
14,920,935 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i dont want to login with help of login control in asp.net using membership.

if i am using login control means i can login the user.but i cant login without login control

this is my code

if i am using below code to login.am getting invalid username or password but i can login in login control

login.aspx

ASP.NET
<fieldset class="login">

                <asp:Label ID="lblerrormsg" ForeColor="Red" runat="server" Text=""></asp:Label>

                <legend>Account Information</legend>
                <table>
                    <tr>
                        <td>
                            <asp:Label ID="Usernamelbl" runat="server" Text="UserName:"></asp:Label>
                        </td>
                        <td>
                            <asp:TextBox ID="txtUserName" Width="120px" runat="server" />
                            <asp:RequiredFieldValidator ID="rfvUser" ErrorMessage="Please enter Username" ControlToValidate="txtUserName" runat="server" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <asp:Label ID="lblpwd" runat="server" Text="Password:"></asp:Label>
                        </td>
                        <td>
                            <asp:TextBox ID="txtPWD" runat="server" Width="120px" TextMode="Password" />
                            <asp:RequiredFieldValidator ID="rfvPWD" runat="server" ControlToValidate="txtPWD" ErrorMessage="Please enter Password" />
                        </td>
                    </tr>
                    <tr>
                        <td>

                        </td>
                        <td>
                            <asp:CheckBox ID="RememberMe" runat="server"/>
                        <asp:Label ID="RememberMeLabel" runat="server" AssociatedControlID="RememberMe" CssClass="inline">Keep me logged in</asp:Label>
                        </td>
                    </tr>
                    <tr>
                        <td></td>
                        <td>
                            <asp:Button ID="loginbtn" runat="server" Text="LogIn" OnClick="loginbtn_Click" />
                        </td>
                    </tr>

                </table>

            </fieldset>

this is code behind page

C#
protected void loginbtn_Click(object sender, EventArgs e)
       {
           if (FormsAuthentication.Authenticate(txtUserName.Text, txtPWD.Text))
           {
               FormsAuthentication.RedirectFromLoginPage(txtUserName.Text, RememberMe.Checked);

               Response.Redirect("home.aspx");

           }
           else
           {
               lblerrormsg.Text = "Invalid UserName or Password";
               lblerrormsg.ForeColor = System.Drawing.Color.Red;
           }

       }
Posted
Updated 7-Jan-14 19:55pm
v3

1 solution

Refer - How to use forms authentication without login control?[^].
C#
public void Login_OnClick(object sender, EventArgs args)
{
    if (Membership.ValidateUser(Username.Text,Password.Text))
    {
         FormsAuthentication.RedirectFromLoginPage(Username.Text,
         NotPublicCheckBox.Checked);
    }
    else
        Msg.Text = "Login failed.";
}
Comments
raj1990m 9-Jan-14 2:06am
   
its working tadit.thanks
now i want to close login window(its small window like ajax popup window) when user authenticate is success.if username and password is success means its redirect to some other page..solve this problem

this my code

login.aspx

<script type="text/javascript">

function CloseWindow() {
window.opener.location.href = 'welcome.aspx';
window.close();

}
</script>

code behind page

if(Membership.ValidateUser(txtUserName.Text,txtPWD.Text)==true)
{
Session["username"] = User.Identity.Name;
FormsAuthentication.RedirectFromLoginPage(txtUserName.Text, true);

FormsAuthentication.RedirectFromLoginPage(txtUserName.Text, RememberMe.Checked);
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "popup", "<script type='text/javascript'>CloseWindow();</script>", true);
}
else
{
msg.Text="invalid username and password";
}
   
I would suggest you to add another question and give me the link here. :)
raj1990m 9-Jan-14 4:55am
   
cant solve my query?
   
You have not explained your query yet. You have only posted the codes here.
That's why Ii suggested you to add another question explaining the problem and give me the link here as this thread is already resolved and we need to talk in a different question.

It is better to continue in another question, otherwise it will be a confusion for the visitors.

Thanks,
Tadit
raj1990m 10-Jan-14 0:08am
   
http://www.codeproject.com/Questions/708829/how-to-close-javascript-popup-window-when-user-log

solve this
raj1990m 29-Jan-14 12:02pm
   
http://www.codeproject.com/Questions/717205/i-cant-update-table-value-using-editable-property

solve this problem
ashishdhyani90 25-Jul-18 8:36am
   
jkl

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900