How to use forms authentication without login control?

asp.net, asp.net-authentication, asp.net-membership, custom-membershipprovider, forms-authentication

Solution

I am assuming that instead of using a login control, you are using a few textboxes(eg username/password) and a logon button. The code could look something like this:

In your aspx file

<asp:Textbox runat="server" ID="Username"/>
<asp:Textbox runat="server" ID="Password"/>
<asp:Button runat="server" ID="Login" OnClick="Login_OnClick"/>

<asp:Label runat="server" ID="Msg" >

And on server side:

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.";
}

The forms authentication usually consists of 2 parts:

- Calling membership API to authenticate/validate the user

- Using FormsAuthentication API to log the user on (creating auth cookies, etc)

For more info look at these articles:

- http://msdn.microsoft.com/en-us/library/aa480476.aspx

- http://msdn.microsoft.com/en-us/library/system.web.security.formsauthentication.redirectfromloginpage.aspx

- http://msdn.microsoft.com/en-us/library/system.web.security.formsauthentication.authenticate.aspx

Problem

How to use forms authentication without login control.I don't want to use asp.net login control in my site.But i have to implement forms authentication and to validate users in my database.

Original source