Method 1: create an identity ticket and write a cookie
// Create an authentication ticket
Formsauthenticationticket authticket = New Formsauthenticationticket ( 1 , " Userinfo. Username " , Datetime. Now, datetime. Now. addminutes ( 20 ), False , " Roles " );
// Create an encrypted string for the authentication ticket
String Encryptedticket = Formsauthentication. Encrypt (authticket );
// Store encrypted strings in httpcookie objects
Httpcookie authcookie = New Httpcookie (formsauthentication. formscookiename, encryptedticket );
// Add the cookie to the cookie set returned to the user's browser
Response. Cookies. Add (authcookie );
// Redirect the user to the login page
Response. Redirect ( " ~ /Default. aspx " );
Method 2: Use the formsauthentication class to automatically create an identity ticket to write a cookie.
Formsauthentication. redirectfromloginpage (username, True );
// Write the cookie according to the name you set.
Method 3: Use the logon control ASP: Login Without writingCode.