// Login page:
// Set cookie and user. Identity. Name
// Set the user's cookie value
Formsauthentication. setauthcookie (login1.username, true );
// Obtain the user's cookie
Httpcookie cookie = request. Cookies [formsauthentication. formscookiename];
// Httpcookie cookie = formsauthentication. getauthcookie (login1.username, false );
// Add the cookie domain and expiration date to the user's cookie value
// Rewrite the user cookie with the same name to the client
// Cookie. expires = datetime. Now. addminutes (3 );
// Httpcontext. Current. response. setcookie (cookie );
Formsauthenticationticket oldticket = formsauthentication. decrypt (cookie. value );
Formsauthenticationticket newticket = new formsauthenticationticket (oldticket. version,
Oldticket. Name,
Oldticket. issuedate,
Datetime. Now. addminutes (3 ),
Oldticket. ispersistent,
Oldticket. userdata,
Formsauthentication. formscookiepath );
// Cookie. Domain = "taeco"; // cookiedomain;
Cookie. value = formsauthentication. Encrypt (newticket );
Cookie. expires = oldticket. issuedate. addminutes (2 );
Httpcontext. Current. response. setcookie (cookie );
// Other pages can control the timeout of the current user's cookie
Session ["nowtime"] = datetime. now;
Httpcookie cookie = httpcontext. Current. Request. Cookies [formsauthentication. formscookiename];
Formsauthenticationticket oldticket = formsauthentication. decrypt (cookie. value );
Timespan timediff = oldticket. expiration. addminutes (1)-oldticket. issuedate;
Formsauthenticationticket newticket = new formsauthenticationticket (oldticket. version,
Oldticket. Name,
Datetime. parse (session ["nowtime"]. tostring ()),
Datetime. Now. Add (timediff ),
Oldticket. ispersistent,
Oldticket. userdata,
Formsauthentication. formscookiepath );
// Cookie. Domain = "taeco"; // cookiedomain;
Cookie. value = formsauthentication. Encrypt (newticket );
// Cookie. expires = datetime. Now. addminutes (3 );
Httpcontext. Current. response. setcookie (cookie );
// Display status and value
// Get the web application configuration.
System. configuration. Configuration configuration =
Webconfigurationmanager. openwebconfiguration ("~ ");
// Get the external authentication section.
Authenticationsection =
(Authenticationsection) configuration. getsection (
"System. Web/authentication ");
// Get the external forms section.
Formsauthenticationconfiguration formsauthentication =
Authenticationsection. forms;
System. timespan currenttimeout =
Formsauthentication. Timeout;
Label2.text = "forms cookieless:" + formsauthentication. cookieless. tostring ();
Label2.text + = "<br/> forms defaulturl:" + formsauthentication. defaulturl. tostring ();
String domain = string. empty;
If (formsauthentication. Domain = NULL)
Domain = "null ";
Else formsauthentication. domain. tostring ();
Label2.text + = "<br/> forms domain:" + domain;
Label2.text + = "<br/> forms enablecrossappredirects:" + formsauthentication. enablecrossappredirects. tostring ();
Label2.text + = "<br/> forms loginurl:" + formsauthentication. loginurl;
Label2.text + = "<br/> forms name:" + formsauthentication. Name;
Label2.text + = "<br/> forms protection:" + formsauthentication. Protection. tostring ();
Label2.text + = "<br/> forms requiressl:" + formsauthentication. requiressl. tostring ();
Label2.text + = "<br/> forms path:" + formsauthentication. Path. tostring ();
Label2.text + = "<br/> forms slidingexpiration:" + formsauthentication. slidingexpiration. tostring ();
Label2.text + = "<br/> forms Timeout:" + formsauthentication. Timeout. tostring ();
Label2.text + = "<br/> session cookiemode:" + session. cookiemode. tostring ();
Label2.text + = "<br/> session iscookieless:" + session. iscookieless. tostring ();
Label2.text + = "<br/> session mode:" + session. mode. tostring ();
Label2.text + = "<br/> Session Timeout:" + session. Timeout. tostring ();
// If (request. Cookies. Count = 0)
//{
// Httpcookie cookie = new httpcookie ("user", "test ");
// Response. Cookies. Add (cookie );
//}
// For (INT I = 0; I <request. Cookies. Count; I ++)
//{
// Httpcookie cookie = request. Cookies [I];
// Cookie. expires = datetime. Now. addminutes (3 );
// Response. Cookies. Set (cookie );
//}
If (request. Cookies. Count> 0)
{
Httpcookie cookie = httpcontext. Current. Request. Cookies [formsauthentication. formscookiename];
Formsauthenticationticket oldticket = formsauthentication. decrypt (cookie. value );
If (oldticket! = NULL)
{
Label2.text + = "<br/> cookie issuedate:" + oldticket. issuedate. tostring ();
Label2.text + = "<br/> cookie expires:" + oldticket. expiration. tostring ();
// Label2.text + = "<br/> cookie name:" + Cookie. Name. tostring ();
// Label2.text + = "<br/> Cookie Path:" + Cookie. Path. tostring ();
// Label2.text + = "<br/> cookie secure:" + Cookie. Secure. tostring ();
// Label2.text + = "<br/> cookie value:" + Cookie. value. tostring ();
// Label2.text + = "<br/> cookie Timeout:" + Cookie. expires. tostring ();
}
}
If (session ["nowtime"] = NULL) session ["nowtime"] = datetime. now;
Label3.text = "Start:" + session ["nowtime"]. tostring ();
// Response. Write ("Timeout:" + formsauthentication. Timeout. tostring ());
// Set the timeout.
// Formsauthentication. Timeout =
// System. timespan. fromminutes (10 );