ASP. NET permission Control for HTML page elements (2)

Source: Internet
Author: User

This is the first step in permission control. The scan interface obtains the information of the elements to be assigned permissions and stores them in the database.

This step is divided into three small steps:

(1) mark the elements of the interface for permission assignment

(2) scan the page to obtain the Element Information of the permission to be assigned. (ID, title, hierarchical relationship)

(3). Save it to the database.

1. Mark the elements of the interface for permission assignment.

At the beginning of scanning, I found it difficult because there were too many HTML elements and many hierarchical relationships. At the beginning, the <div> label is used to represent the element of the HTML permission allocation. It is found that this solution is not good, for example, if you add a user button to a DIV, the style of the button will change and you have to adjust the style. The KS system I am working on now has nearly 100 interfaces, and the style has been determined by the current interface, after adjusting the CSS and adding the DIV, you have to re-tune the interface. I thought about the problem for two or three days. Finally, I thought about customizing an HTML element Tag: <box> </box> Add the ID and Title to the tag: <box id = "AddID" Title = "Add button"> </box>, this label is used to mark the elements of the permissions to be assigned. In this way, you do not need to change the style and obtain the desired information. The modified background code is as follows:
Copy codeThe Code is as follows:
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Meta name = "Author" content = "kudychen@gmail.com"/>
<Meta http-equiv = "X-UA-Compatible" content = "IE = EmulateIE7"/>
<Title> User Management-query a user </title>

<Script src = ".../../js/DIV/jquery. js"> </script>
<Script src = ".../../js/DIV. js"> </script>
<Link href = ".../../css/admin.global.css" rel = "stylesheet" type = "text/css"/>
<Link href = ".../../css/admin.content.css" rel = "stylesheet" type = "text/css"/>

<Style type = "text/css">
. Btn-middle {
Width: 76px;
}
</Style>

</Head>
<Body>
<Form id = "Form" method = "post" runat = "server">
<% -- Box mark main start mark -- %>
<Box id = "main" title = "main">
<Div class = "location"> current location: User Management-> query user </div>

<Div class = "blank10"> </div>
<% -- Box mark QueryUser start mark -- %>
<Box id = "QueryUser" title = "query user">
<Div class = "search block">
<Div class = "h">
<Span class = "icon-sprite icon-magnifier"> </span>
<H3> quick search </Div>
<Div class = "tl corner"> </div>
<Div class = "tr corner"> </div>
<Div class = "bl corner"> </div>
<Div class = "br corner"> </div>
<Div class = "cnt-wp">
<Div class = "cnt">
<Div class = "search-bar">
<Label class = "first txt-green"> User name: </label>
<Input value = "" type = "text" name = "username" id = "username" class = "input-small"/>


<Asp: LinkButton ID = "lbtQuery" class = "btn-Example" runat = "server"
OnClick = "lbtQuery_Click" Width = "58px"> <span> query </span> </asp: LinkButton>

<% -- Box mark AddUser start mark -- %>
<Box id = "AddUser" title = "Add User">
<A class = "btn-lit btn-middle" href = "AdmAddUser. aspx">
<Span> Add a user </span>
</A>
</Box>
<% -- Box mark AddUser end mark -- %>
</Div>
</Div>
</Div>
</Div>
</Box>
<% -- Box mark QueryUser end mark -- %>

<% -- Box mark UserList start mark -- %>
<Box id = "UserList" title = "User List">
<Span class = "block">
<Div class = "tl corner"> </div>
<Div class = "tr corner"> </div>
<Div class = "bl corner"> </div>
<Div class = "br corner"> </div>
<Div class = "cnt-wp">
<Div class = "cnt">
<Div class = "h">
<Span class = "icon-sprite icon-list"> </span>
<H3> User List </Div>
<Div class = "blank10"> </div>

<Asp: Repeater ID = "rpUserInfo" runat = "server" onitemcommand = "rpUserInfo_ItemCommand">
<HeaderTemplate>
<Table class = "data-table history" id = "mainTable" border = "0" cellspacing = "0" cellpadding = "0">
<Tr>
<Th scope = "col"> User Name </th>
<Th scope = "col"> role </th>
<Th scope = "col"> Operation Records </th>
<Th scope = "col"> edit </th>
</Tr>
</HeaderTemplate>
<ItemTemplate>
<Tr>
<Td class = "txt160 c"> <% # Eval ("UserName") %> </td>
<Td class = "txt c"> <% # Eval ("RoleName") %> </td>
<Td class = "txt80 c"> <a href = "AdmOperatorRecord. aspx? UserId = <% # Eval ("UserNo") %> "title =" operation record "> operation record </a> </td>
<Td class = "icon">
<% -- Box mark EditUserInfo start mark -- %>
<Box id = "EditUserInfo" title = "edit user">
<A class = "opt" title = "edit" href = "AdmUpdateUser. aspx? UserId = <% # Eval ("UserNo") %> ">
<Span class = "icon-sprite icon-edit">
</Span>
</A>
</Box>
<% -- Box mark EditUserInfo end mark -- %>
</Td>
</Tr>
</ItemTemplate>
<FooterTemplate>
</Table>
</FooterTemplate>
</Asp: Repeater>
</Div>
</Div>
</Span>
<Span id = "spanFirst"> first page </span> <span id = "spanPre"> previous page </span> <span id = "spanNext"> next page </span> <span id = "spanLast"> last page </span> page <span id = "spanPageNum"> </span>/total <span id = "spanTotalPage"> </span> page
</Box>
<% -- Box mark UserList end mark -- %>
</Box>
<% -- Box mark main end mark -- %>
</Form>
</Body>
</Html>


2. Scan the page to obtain the Element Information of the permission to be assigned.

Because the <box> element represents the permission element on the interface, it is better to scan it, but there are still a lot of problems, and the final solution is solved, the most difficult thing is to scan the parent-child relationship between two <box>. The following is the JS Code:
Copy codeThe Code is as follows:
$ (Document). ready (function (){

Var rootboxs = document. getElementById ("main ");
Var child = rootboxs. childNodes;
Findchildbox (child)


});
// Search for subnodes
Function findchildbox (parentNode ){

For (var I = 0; I <parentNode. length; I ++ ){
///
If (parentNode [I]. nodeName = "BOX "){

Var childboxId = parentNode [I]. id;
Var childboxTitle = encodeURI (parentNode [I]. title );
Var parentbox = findparentbox (parentNode [I]. parentNode );
Var parentboxId = parentbox. id;
If (window. XMLHttpRequest ){
// IE7 abve, firefox, chrome ^
Xmlhttp = new XMLHttpRequest ();
// To be compatible with some javasillar browsers, failure to respond to problems caused by a response from the server starting with xml
If (xmlhttp. overrideMimeType ){
Xmlhttp. overrideMimeType ('text/xml ');
}
}
Else if (window. ActiveXObject ){
// IE5 \ IE6
Xmlhttp = new activeXObject ("Microsoft. XMLHTTP ");
}
If (xmlhttp = null | xmlhttp = undefined ){
Alert ("con't create XMLHttpRequest Object ");
}
// Register the callback function
Xmlhttp. onreadystatechange = callback;
// Send information

Xmlhttp. open ('get', '.../Manager/RoleManager/AddBox. ashx? ChildboxId = '+ childboxId +' & childboxTitle = '+ childboxTitle +' & parentboxId = '+ parentboxId, true );
Xmlhttp. send (null );


Function callback (){
// Determine whether the interaction is complete and whether the interaction is returned correctly
If (xmlhttp. readyState = 4 & xmlhttp. status = 200 ){

}
}

}

Findchildbox (parentNode [I]. childNodes)

}

}

// Query the parent node
Function findparentbox (child ){

If (child. nodeName = "BOX "){
Return child;
} Else {
Return findparentbox (child. parentNode)

}

}

3. store the data in the database.

I used AJAX to store data in the database. I encountered a problem at the beginning, this is because the time required for scanning the interface is too short. When the first data is not inserted into the database, the second data entry will be replaced by the second data record. this causes a problem with the data stored in the database. At first, I was planning to add a delay in JS, but the result table name would not work. Then I add a lock-like thing to a program, which is regarded as a delay. The data stored in this way will not be wrong. The following code is used:
Copy codeThe Code is as follows:
Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Web;
Using BLL. Manager. RoleUserManagerBLL;
Using System. Data;
Using System. Text;
Using Model;
Using BLL;

Namespace ExamSystemV3.Manager. RoleManager
{
/// <Summary>
/// AddBox Summary
/// </Summary>
Public class AddBox: IHttpHandler
{

Public void ProcessRequest (HttpContext context)
{
Context. Response. ContentType = "text/plain ";
System. Threading. Thread. Sleep (1000 );
DIVEntity EDiv = new DIVEntity ();
AdmDIVManager admDIVManager = new AdmDIVManager ();
PublicBLL publicBll = new PublicBLL ();
String strChildBoxId = "";
String strChildBoxTitle = "";

StrChildBoxId = context. Request. QueryString ["childboxId"]. ToString (). Trim ();
StrChildBoxTitle = context. Server. UrlDecode (context. Request. QueryString ["childboxTitle"]. ToString (). Trim ());
String strParentBoxId = context. Request. QueryString ["parentboxId"]. ToString (). Trim ();;
String strState = "yes ";
String strDateTime = publicBll. GetDate ();
String strIP = publicBll. GetWebClientIp ();
String strOperator = "xvshu"; // context. Session ["UserNo"]. ToString (). Trim ();;
EDiv. Id = strChildBoxId;
EDiv. MainRelation = strParentBoxId;
EDiv. DIVName = strChildBoxTitle;
EDiv. DIVDescribe = strChildBoxTitle;
EDiv. Operator = strOperator;
EDiv. OperatorIP = strIP;
EDiv. State = strState;
EDiv. DateTime = strDateTime;
AdmDIVManager. AddDIV (EDiv );
}

Public bool IsReusable
{
Get
{
Return false;
}
}
}
}

The TreeView control is used to display the following information:

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.