In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces "ASP.NET how to control the access of HTML page elements". In the daily operation, I believe many people have doubts about how ASP.NET controls the access of HTML page elements. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts of "ASP.NET how to control the access of HTML page elements". Next, please follow the editor to study!
This is the first step in this permission control, and the scanning interface obtains the information about the elements to which you want to assign permissions and stores them in the database.
This step is divided into three small steps:
(1)。 Mark the elements to which the interface wants to assign permissions
(2)。 The scan interface gets the element information to which you want to assign permissions. (ID, title, hierarchical relationship)
(3)。 Put it in the database.
1. Mark the elements to which the interface wants to assign permissions.
At the beginning of the scan, I found it difficult because there were too many HTML elements and there were many hierarchical relationships. At first, the tag was used to represent the elements that HTML wants to assign permissions. It was found that this solution did not work. For example, add the user button to DIV, then the style of this button changed, and I had to adjust the style. The KS system I am working on now has nearly 100 interfaces. In addition, the current interface has been styled and adjusted CSS. In addition, if DIV is added, the interface will have to be re-adjusted. I have been thinking about this problem for two or three days. Finally, I thought of not customizing a HTML element tag as follows: add ID and Title to:, and use this tag to mark the element to which you want to assign permissions. In this way, you can get the information you want without having to change the style. The background code of the changed interface is:
The copy code is as follows:
User management-query users
. btn-middle {
Width: 76px
}
Current location: user Management-> query users
Quick search
User name:
Query
Add user
User list
User name
Role
Operation record
Editing
Operation record
First page previous page next page last page / total page
two。 The scan interface gets the element information to which you want to assign permissions.
Because there is this element on the interface to represent the permission element, it is better to scan, but still encountered a lot of problems, and finally solved, the most difficult is to scan the father-son relationship between the two. Here is the JS code:
The copy code is as follows:
$(document) .ready (function () {
Var rootboxs = document.getElementById ("main")
Var child = rootboxs.childNodes
Findchildbox (child)
});
/ / search for child nodes
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][xss_clean]); var parentboxId = parentbox.id; if (window.XMLHttpRequest) { //IE7 above,firefox,chrome^^ xmlhttp = new XMLHttpRequest(); //为了兼容部分Mozillar浏览器,当来自服务器响应开头不是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"); } //注册回调函数 xmlhttp.onreadystatechange = callback; //发送信息 xmlhttp.open('GET', '../../Manager/RoleManager/AddBox.ashx?childboxId=' + childboxId + '&childboxTitle=' + childboxTitle + '&parentboxId=' + parentboxId, true); xmlhttp.send(null); function callback() { //判断交互是否完成,是否正确返回 if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { } } } findchildbox(parentNode[i].childNodes) } } //查询父节点 function findparentbox(child) { if (child.nodeName == "BOX") { return child; } else { return findparentbox(child[xss_clean]) } } 3.存入数据库中。 利用AJAX存入到数据库中,一开始就遇到了问题,因为扫描界面所需要的时间太短在还没有把第一条数据插入到数据库的时候第二条数据就来了这样导致了第一条数据的部分信息就会被第二条记录替代了导致存入数据库的数据出现了问题。一开始我是打算在JS那里加上个延迟,结果表名不行。然后我就在一班程序里面加入一个类似锁的一个东西,算作延迟吧这样存入的数据就不会错误了下面是代码: 复制代码 代码如下: 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 { /// /// AddBox 的摘要说明 /// 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 = "是"; 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; } } } } 利用TreeView控件显示出来如下图:At this point, the study on "how ASP.NET controls the permissions of HTML page elements" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.