search
HomeBackend DevelopmentC#.Net TutorialASP.NET controls permissions on HTML page elements (2)

This is the first step in this permission control. The scanning interface obtains the information about the elements to be assigned permissions and stores it in the database.

This step is divided into three small steps:

(1). Mark the elements on the interface to which permissions are to be assigned

(2). Scan the interface to obtain the element information for which permissions are to be assigned . (ID, title, hierarchical relationship)

(3). Store in the database.

1. Mark the elements on the interface to which permissions are to be assigned.

When scanning, I found it difficult at first because there were too many HTML elements and many hierarchical relationships. At the beginning, I used the

tag to represent the HTML elements to which permissions were assigned. I found that this solution did not work. For example, if I added a DIV to the add user button, the style of the button would change and I would have to adjust the style of the KS system I am currently working on. There are nearly 100 interfaces. In addition, the style of the current interface has been determined and the CSS has been adjusted. In addition, if DIV is added, the interface will have to be re-adjusted. I thought about this issue for two or three days, and finally I thought about customizing it. An HTML element tag is: Add ID and Title to this tag: , use this tag to mark the elements to which permissions are to be assigned. In this way, you can get the required information without changing the style. The interface background code after the change is:
<!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>用户管理——查询用户</title> 

<script src="../../js/DIV/jquery.js"></script> 
<script src="../../js/DIV/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标记 main 开始标记--%> 
<box id="main" title="主要"> 
<div class="location">当前位置:用户管理 -> 查询用户</div> 

<div class="blank10"></div> 
<%--box标记 QueryUser 开始标记--%> 
<box id="QueryUser" title="查询用户"> 
<div class="search block" > 
<div class="h"> 
<span class="icon-sprite icon-magnifier"></span> 
<h3 id="快速搜索">快速搜索</h3> 
</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">用户名:</label> 
<input value="" type="text" name="username" id="username" class="input-small" /> 


<asp:LinkButton ID="lbtQuery" class="btn-lit" runat="server" 
OnClick="lbtQuery_Click" Width="58px"><span >查询</span></asp:LinkButton> 

<%--box标记 AddUser 开始标记--%> 
<box id="AddUser" title="添加用户"> 
<a class="btn-lit btn-middle" href="AdmAddUser.aspx"> 
<span>添加用户</span> 
</a> 
</box> 
<%--box标记 AddUser结束标记--%> 
</div> 
</div> 
</div> 
</div> 
</box> 
<%--box标记 QueryUser结束标记--%> 

<%--box标记 UserList开始标记--%> 
<box id="UserList" title="用户列表"> 
<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 id="用户列表">用户列表</h3> 
</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">用户名称</th> 
<th scope="col">角色</th> 
<th scope="col">操作记录</th> 
<th scope="col">编辑</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="操作记录">操作记录</a></td> 
<td class="icon"> 
<%--box标记 EditUserInfo开始标记--%> 
<box id="EditUserInfo" title="编辑用户"> 
<a class="opt" title="编辑" href="AdmUpdateUser.aspx?UserId=<%#Eval("UserNo") %>"> 
<span class="icon-sprite icon-edit"> 
</span> 
</a> 
</box> 
<%--box标记 EditUserInfo结束标记--%> 
</td> 
</tr> 
</ItemTemplate> 
<FooterTemplate> 
</table> 
</FooterTemplate> 
</asp:Repeater> 
</div> 
</div> 
</span> 
<span id="spanFirst">第一页</span> <span id="spanPre">上一页</span> <span id="spanNext">下一页</span> <span id="spanLast">最后一页</span> 第<span id="spanPageNum"></span>页/共<span id="spanTotalPage"></span>页 
</box> 
<%--box标记 UserList 结束标记--%> 
</box> 
<%--box标记 main 结束标记--%> 
</form> 
</body> 
</html>

2. Scan the interface to obtain the element information to which permissions are to be assigned.

Since there is a element on the interface to represent the permission element, it is easier to scan. However, we still encountered a lot of problems, which were finally solved. The most difficult thing was to scan out The parent-child relationship between two . The following is the JS code:

$(document).ready(function () { 

var rootboxs = document.getElementById("main"); 
var child = rootboxs.childNodes; 
findchildbox(child) 


}); 
//搜寻子节点 
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 above,firefox,chrome^^ 
xmlhttp = new XMLHttpRequest(); 
//为了兼容部分Mozillar浏览器,当来自服务器响应开头不是xml,导致的无法响应问题 
if (xmlhttp.overrideMimeType) { 
xmlhttp.overrideMimeType(&#39;text/xml&#39;); 
} 
} 
else if (window.ActiveXObject) { 
//IE5\IE6 
xmlhttp = new activeXObject("Microsoft.XMLHTTP"); 
} 
if (xmlhttp == null || xmlhttp == undefined) { 
alert("con&#39;t create XMLHttpRequest Object"); 
} 
//注册回调函数 
xmlhttp.onreadystatechange = callback; 
//发送信息 

xmlhttp.open(&#39;GET&#39;, &#39;../../Manager/RoleManager/AddBox.ashx?childboxId=&#39; + childboxId + &#39;&childboxTitle=&#39; + childboxTitle + &#39;&parentboxId=&#39; + 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.parentNode) 

} 

}

3. Store in the database.

Using AJAX to save into the database, we encountered problems at the beginning, because the time required to scan the interface was too short, and the second piece of data came before the first piece of data was inserted into the database. This causes part of the information in the first piece of data to be replaced by the second record, causing problems with the data stored in the database. At first, I planned to add a delay in JS, but the table name didn't work. Then I added something similar to a lock into a class of programs, and counted it as a delay so that the stored data would not be wrong. Here is the code:

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

Use the TreeView control to display it as shown below:

ASP.NET controls permissions on HTML page elements (2)

For more ASP.NET permission control on HTML page elements (2), please pay attention to the PHP Chinese website for related articles!


Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
From Web to Desktop: The Versatility of C# .NETFrom Web to Desktop: The Versatility of C# .NETApr 15, 2025 am 12:07 AM

C#.NETisversatileforbothwebanddesktopdevelopment.1)Forweb,useASP.NETfordynamicapplications.2)Fordesktop,employWindowsFormsorWPFforrichinterfaces.3)UseXamarinforcross-platformdevelopment,enablingcodesharingacrossWindows,macOS,Linux,andmobiledevices.

C# .NET and the Future: Adapting to New TechnologiesC# .NET and the Future: Adapting to New TechnologiesApr 14, 2025 am 12:06 AM

C# and .NET adapt to the needs of emerging technologies through continuous updates and optimizations. 1) C# 9.0 and .NET5 introduce record type and performance optimization. 2) .NETCore enhances cloud native and containerized support. 3) ASP.NETCore integrates with modern web technologies. 4) ML.NET supports machine learning and artificial intelligence. 5) Asynchronous programming and best practices improve performance.

Is C# .NET Right for You? Evaluating its ApplicabilityIs C# .NET Right for You? Evaluating its ApplicabilityApr 13, 2025 am 12:03 AM

C#.NETissuitableforenterprise-levelapplicationswithintheMicrosoftecosystemduetoitsstrongtyping,richlibraries,androbustperformance.However,itmaynotbeidealforcross-platformdevelopmentorwhenrawspeediscritical,wherelanguageslikeRustorGomightbepreferable.

C# Code within .NET: Exploring the Programming ProcessC# Code within .NET: Exploring the Programming ProcessApr 12, 2025 am 12:02 AM

The programming process of C# in .NET includes the following steps: 1) writing C# code, 2) compiling into an intermediate language (IL), and 3) executing by the .NET runtime (CLR). The advantages of C# in .NET are its modern syntax, powerful type system and tight integration with the .NET framework, suitable for various development scenarios from desktop applications to web services.

C# .NET: Exploring Core Concepts and Programming FundamentalsC# .NET: Exploring Core Concepts and Programming FundamentalsApr 10, 2025 am 09:32 AM

C# is a modern, object-oriented programming language developed by Microsoft and as part of the .NET framework. 1.C# supports object-oriented programming (OOP), including encapsulation, inheritance and polymorphism. 2. Asynchronous programming in C# is implemented through async and await keywords to improve application responsiveness. 3. Use LINQ to process data collections concisely. 4. Common errors include null reference exceptions and index out-of-range exceptions. Debugging skills include using a debugger and exception handling. 5. Performance optimization includes using StringBuilder and avoiding unnecessary packing and unboxing.

Testing C# .NET Applications: Unit, Integration, and End-to-End TestingTesting C# .NET Applications: Unit, Integration, and End-to-End TestingApr 09, 2025 am 12:04 AM

Testing strategies for C#.NET applications include unit testing, integration testing, and end-to-end testing. 1. Unit testing ensures that the minimum unit of the code works independently, using the MSTest, NUnit or xUnit framework. 2. Integrated tests verify the functions of multiple units combined, commonly used simulated data and external services. 3. End-to-end testing simulates the user's complete operation process, and Selenium is usually used for automated testing.

Advanced C# .NET Tutorial: Ace Your Next Senior Developer InterviewAdvanced C# .NET Tutorial: Ace Your Next Senior Developer InterviewApr 08, 2025 am 12:06 AM

Interview with C# senior developer requires mastering core knowledge such as asynchronous programming, LINQ, and internal working principles of .NET frameworks. 1. Asynchronous programming simplifies operations through async and await to improve application responsiveness. 2.LINQ operates data in SQL style and pay attention to performance. 3. The CLR of the NET framework manages memory, and garbage collection needs to be used with caution.

C# .NET Interview Questions & Answers: Level Up Your ExpertiseC# .NET Interview Questions & Answers: Level Up Your ExpertiseApr 07, 2025 am 12:01 AM

C#.NET interview questions and answers include basic knowledge, core concepts, and advanced usage. 1) Basic knowledge: C# is an object-oriented language developed by Microsoft and is mainly used in the .NET framework. 2) Core concepts: Delegation and events allow dynamic binding methods, and LINQ provides powerful query functions. 3) Advanced usage: Asynchronous programming improves responsiveness, and expression trees are used for dynamic code construction.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools