ASP.NET對HTML頁面元素進行許可權控制(三)

來源:互聯網
上載者:User
上一篇部落格中有些沒有考慮到的東西這次更改一下代碼如下:

介面前台:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AdmShowDIV.aspx.cs" Inherits="ExamSystemV3.Manager.RoleManager.AdmShowDIV" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <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" type="text/javascript"></script> <script src="../../js/DIV/DIV.js" type="text/ecmascript"></script> <link href="../../css/admin.global.css" rel="stylesheet" type="text/css" /> <link href="../../css/admin.content.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="../../../js/jquery.easyui.min.js"></script> <script type="text/javascript" src="../../js/jquery-1.4.2.min.js"></script> <script type="text/javascript" src="../../js/jquery.utils.js"></script> <link href="../../jBox/Skins/Green/jbox.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="../../jBox/jquery.jBox-2.3.min.js"></script> <script type="text/javascript" src="../../js/admin.js"></script> <script type="text/javascript" src="../../js/SimpleTree.js"></script> </head> <body> <form id="form1" runat="server"> <div class="container"> <div class="location">當前位置:介面元素管理 -> 查看介面元素</div> <div class="blank10"></div> <div class="search block"> <div class="h"> <span class="icon-sprite icon-magnifier"></span> <h3>快速搜尋</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" id="SelectRole"> <label class="txt-green">請選擇介面:</label> <asp:DropDownList ID="DdlWindowsName" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DdlWindowsName_SelectedIndexChanged"> </asp:DropDownList> <a class="btn-lit" href="#" onclick="WindowsInfo()"><span>掃描介面資訊</span></a> </div> </div> </div> </div> </div> <div class="block"> <div class="h"> <span class="icon-sprite icon-list"></span> <h3>介面詳情</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"> <iframe id="frmWindows" runat="server" frameborder="0" marginheight="0" marginwidth="0" scrolling="auto" style=" display: inline; height: 400px;" width="75%" ></iframe> <iframe id="frmUpdateDIV" runat="server" frameborder="0" marginheight="0" marginwidth="0" scrolling="auto" style="display: inline; height: 400px; width: 24%;"></iframe> </div> </div> </div> </form> </body> </html>

介面後台:

using BLL.Manager.RoleUserManagerBLL; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace ExamSystemV3.Manager.RoleManager { public partial class AdmShowDIV : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { string strLike=""; if (!IsPostBack) { //綁定介面 DataBindWindows(strLike); } } /// <summary> /// 綁定所有介面 /// </summary> /// <param name="strLike"></param> public void DataBindWindows(string strLike) { DataTable dt = new DataTable(); AdmWindowsManager admWindowsManager = new AdmWindowsManager(); //查出所有的介面 dt = admWindowsManager.QueryWindowInfo(strLike); //綁定介面資訊 DdlWindowsName.DataSource = dt; DdlWindowsName.DataValueField = "Id"; DdlWindowsName.DataTextField = "WindowsName"; DdlWindowsName.DataBind(); } protected void DdlWindowsName_SelectedIndexChanged(object sender, EventArgs e) { DataTable dt = new DataTable(); string strLike = ""; AdmWindowsManager admWindowsManager = new AdmWindowsManager(); //查出介面的資訊 dt = admWindowsManager.QueryWindowInfo(strLike); string strWindowsId=DdlWindowsName.SelectedValue.ToString().Trim(); strLike = "Id='"+strWindowsId+"'"; DataRow[] rows =dt.Select (strLike); //獲得路徑 string strURL = rows[0]["WindowsURL"].ToString (); strURL = "../../" + strURL; frmWindows.Attributes["src"]=strURL; frmUpdateDIV.Attributes["src"] = "AdmUpdateDIV.aspx?WindowsID='" + strWindowsId + "'"; } } }

JS:

var WindowsID; function WindowsInfo() { //擷取ifrm var frmWindows = document.getElementById("frmWindows").contentWindow; //擷取介面ID WindowsID = document.getElementById("DdlWindowsName").value; var rootboxs = frmWindows.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+'&windowsId='+WindowsID, 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) } }

一般處理常式:

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(); TR_WindowsDIVEntity EWindowsDiv = new TR_WindowsDIVEntity(); 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 strWindowsId = context.Request.QueryString["windowsId"].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; //給WindowsDIV實體類賦值 EWindowsDiv.DIVID = strChildBoxId; EWindowsDiv.WindowsID = strWindowsId; EWindowsDiv.IsVisible = "是"; EWindowsDiv.Operator = strOperator; EWindowsDiv.OperatorIP = strIP; EWindowsDiv.DateTime = strDateTime; //添加DIV admDIVManager.AddDIV(EDiv,EWindowsDiv); } public bool IsReusable { get { return false; } } } }
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.