Asp. NET permissions control for HTML page elements (ii)

Source: Internet
Author: User
This is the first step in this permission control, and the scanning interface takes the information of the elements to be assigned to the permissions to be stored in the database.

This step is divided into three small steps:

(1). The element that marks the permission to be assigned to the interface

(2). The scan interface gets the element information for the permission to be assigned. (ID, title, hierarchical relationship)

(3). Deposit into the database.

1. Mark the elements of the interface that you want to assign permissions to.

At the beginning of the scan I found it difficult because there are too many HTML elements and a lot of hierarchical relationships. Start with the <div> tag to represent the HTML to assign permissions to the element, found that this scheme is not possible, such as adding a user button to add a div then the style of the button changed the style I now do the KS system has nearly 100 interfaces, plus now the interface has been determined by the style , adjust the CSS, plus div words so have to re-adjust the interface, on this question for two or three days, and finally I think of the HTML element tag to:<box></box> for this tag plus ID and title: <box id= " Addid "title=" add button "&GT;&LT;/BOX&GT; Use this tag to mark the element that you want to assign permissions to. This way, you can get the information you want without changing the style. After changing the interface background code is:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> 

2. The scan interface gets the element information for the permission to be assigned.

Because the interface has <box> this element to represent the elements of the permission, so that the scan is better but still encountered a lot of problems, eventually solved, the most difficult is to scan out two of the parent-child relationship between <box>. Here is the JS code:

$ (document). Ready (function () {var rootboxs = document.getElementById ("main"), var child = Rootboxs.childnodes; Findchil Dbox (Child)}); Search child node function Findchildbox (parentnode) {for (var i = 0; i < parentnode.length; i++) {//if (Parentnode[i].nodenam E = = "box") {var childboxid = parentnode[i].id; var childboxtitle = encodeURI (parentnode[i].title); var parentbox = FINDP Arentbox (Parentnode[i].parentnode); var parentboxid = parentbox.id; if (window. XMLHttpRequest) {//ie7 above,firefox,chrome^^ xmlhttp = new XMLHttpRequest ();//In order to be compatible with part of the Mozillar browser, when the response from the server starts with not XML, The resulting unresponsive problem 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 callback function Xmlhttp.onreadystatechange = callback; Send Message Xmlhttp.open (' GET ', '. /.. /manager/rolemanager/addbox.ashx?childboxid= ' + Childboxid + ' &chilDboxtitle= ' + childboxtitle + ' &parentboxid= ' + Parentboxid, true); Xmlhttp.send (NULL); function callback () {//determines if the interaction is complete, returns if (Xmlhttp.readystate = = 4 && Xmlhttp.status = =) {}}} Findchildbox (Parentnode[i].childnodes)} }//Query parent node function Findparentbox (child) {if (Child.nodename = = "box") {return child,} else {return Findparentbox (child . parentnode)}}

3. Deposit into the database. The

uses Ajax to deposit into the database, and at first it ran into a problem. Because the scanning interface takes too much time to insert the first piece of data into the database. This results in the first piece of data being replaced by a second record, which causes the data to be stored in the database to become problematic. At first I was going to add a delay to JS, the result table name is not. And then I'm going to add a lock-like thing to the program, which counts as a delay. This is the code that is stored here:

Using System; Using System.Collections.Generic; Using System.Linq; Using System.Web; Using the BLL. MANAGER.ROLEUSERMANAGERBLL; Using System.Data; Using System.Text; Using Model; Using BLL;  namespace ExamSystemV3.Manager.RoleManager {//<summary>///Addbox Summary description///</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;}}} }

Use the TreeView control to display it as:

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.