I. Static pagesCodeAs follows:
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<SCRIPT type = "text/JavaScript" Language = "JavaScript">
// Create a function that is applicable to the XMLHTTPRequest object with multiple browsers
VaR xmlhttpreq = false;
// Create an XMLHTTPRequest object (the main function does not need to be changed)
Function createxmlhttprequest (){
If (window. XMLHttpRequest) {// Mozilla Browser
Xmlhttpreq = new XMLHttpRequest ();
}
else if (window. activexobject) {// IE browser
try {
xmlhttpreq = new activexobject ("msxml2.xmlhttp");
}
Catch (e ){
Try {
Xmlhttpreq = new activexobject ("Microsoft. XMLHTTP ");
}
Catch (e ){}
}
}
}
// Send request function (submit request parameters in XML format)
Function sendrequest (URL ){
Createxmlhttprequest ();
Xmlhttpreq. Open ("Post", URL, false );
Xmlhttpreq. setRequestHeader ("Content-Type", "application/X-WWW-form-urlencoded ");
Xmlhttpreq. Send (); // send the request
}
Sendrequest ("checklogin. aspx"); // only the "check logon page" of the background code is displayed"
VaR I = xmlhttpreq. responsetext;
I = I. substring (0, 1 );
If (I = "0 ")
Location. href = "login. aspx"; // This is the "Logon page"
</SCRIPT>
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> static page </title>
</Head>
<Body>
This is a static page
</Body>
</Html>
2. Create An ASPX page to check whether the page is logged on. The page is not displayed, and only the background code is as follows:
Public partial class checklogin: system. Web. UI. Page
{
Protected void page_load (Object sender, eventargs E)
{
String STR = "www ";
Httpcookie cookie = new httpcookie ("user", STR );
Response. Cookies. Add (cookie );
If (request. Cookies ["user"]! = NULL)
{
Response. Write ("1"); // the output value is xmlhttpreq. responsetext obtained from the static page.
}
Else
Response. Write ("0 ");
}
}