這是這個權限控制的第一步,掃描介面把要分配權限的元素的資訊取得出來存入資料庫。
這一步驟分三小步驟:
(1).標出介面所要分配權限的元素
(2).掃描介面取得所要分配權限的元素資訊。 (ID,標題,層級關係)
(3).存入資料庫。
1.標出介面要分配權限的元素.
在掃描的時候一開始我覺得很難因為HTML元素過多又有很多層級關係。一開始用的是
<!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.掃描介面取得所需分配權限的元素資訊。
由於介面上有了
$(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('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.parentNode) } }
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 { /// <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; } } } }
利用TreeView控制顯示出來如下圖:
更多ASP.NET對HTML頁面元素進行權限控制(二)相關文章請關注PHP中文網!

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

C#和.NET通過不斷的更新和優化,適應了新興技術的需求。 1)C#9.0和.NET5引入了記錄類型和性能優化。 2).NETCore增強了雲原生和容器化支持。 3)ASP.NETCore與現代Web技術集成。 4)ML.NET支持機器學習和人工智能。 5)異步編程和最佳實踐提升了性能。

c#.netissutableforenterprise-levelapplications withemofrosoftecosystemdueToItsStrongTyping,richlibraries,androbustperraries,androbustperformance.however,itmaynotbeidealfoross-platement forment forment forment forvepentment offependment dovelopment toveloperment toveloperment whenrawspeedsportor whenrawspeedseedpolitical politionalitable,

C#在.NET中的編程過程包括以下步驟:1)編寫C#代碼,2)編譯為中間語言(IL),3)由.NET運行時(CLR)執行。 C#在.NET中的優勢在於其現代化語法、強大的類型系統和與.NET框架的緊密集成,適用於從桌面應用到Web服務的各種開發場景。

C#是一種現代、面向對象的編程語言,由微軟開發並作為.NET框架的一部分。 1.C#支持面向對象編程(OOP),包括封裝、繼承和多態。 2.C#中的異步編程通過async和await關鍵字實現,提高應用的響應性。 3.使用LINQ可以簡潔地處理數據集合。 4.常見錯誤包括空引用異常和索引超出範圍異常,調試技巧包括使用調試器和異常處理。 5.性能優化包括使用StringBuilder和避免不必要的裝箱和拆箱。

C#.NET應用的測試策略包括單元測試、集成測試和端到端測試。 1.單元測試確保代碼的最小單元獨立工作,使用MSTest、NUnit或xUnit框架。 2.集成測試驗證多個單元組合的功能,常用模擬數據和外部服務。 3.端到端測試模擬用戶完整操作流程,通常使用Selenium進行自動化測試。

C#高級開發者面試需要掌握異步編程、LINQ、.NET框架內部工作原理等核心知識。 1.異步編程通過async和await簡化操作,提升應用響應性。 2.LINQ以SQL風格操作數據,需注意性能。 3..NET框架的CLR管理內存,垃圾回收需謹慎使用。

C#.NET面試問題和答案包括基礎知識、核心概念和高級用法。 1)基礎知識:C#是微軟開發的面向對象語言,主要用於.NET框架。 2)核心概念:委託和事件允許動態綁定方法,LINQ提供強大查詢功能。 3)高級用法:異步編程提高響應性,表達式樹用於動態代碼構建。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

VSCode Windows 64位元 下載
微軟推出的免費、功能強大的一款IDE編輯器

EditPlus 中文破解版
體積小,語法高亮,不支援程式碼提示功能

SublimeText3 Linux新版
SublimeText3 Linux最新版

Dreamweaver CS6
視覺化網頁開發工具

DVWA
Damn Vulnerable Web App (DVWA) 是一個PHP/MySQL的Web應用程序,非常容易受到攻擊。它的主要目標是成為安全專業人員在合法環境中測試自己的技能和工具的輔助工具,幫助Web開發人員更好地理解保護網路應用程式的過程,並幫助教師/學生在課堂環境中教授/學習Web應用程式安全性。 DVWA的目標是透過簡單直接的介面練習一些最常見的Web漏洞,難度各不相同。請注意,該軟體中