Ajax implements permission control on static html pages

Source: Internet
Author: User

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

}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.