# 副標=安全管制新功能(1) #大標= ASP.NET 2.0網頁安全管理 #眉標= ASP.NET 2.0 #作者=文/王寧疆 =============box 程式1=============== ================= end ================= =============box 程式2============= =================end================== =============Box 程式3============ =================end============= ===================box 標籤1=============== ====================== end ===================== ====================== box 程式4 =================== ======================== end ====================== ====================== box 程式5 ================ Configuration config = WebConfigurationManager.OpenWebConfiguration( Request.ApplicationPath); //取得web.config設定檔 ConfigurationSection section = config.Sections["connectionStrings"]; //取得ConnectionStrings區段 section.SectionInformation.ProtectSection( "DataProtectionConfigurationProvider"); //使用DPAPI加密功能對ConnectionStrings區段執行加密 config.Save(); //將加密後的結果存回web.config設定檔 ======================== end =================== =============== box 程式6 ================= ================= end ==================== ================= box 程式7 ================== AQAAAN以下省略 ==================== end ===================== ================= BOX 程式8 ==================== Configuration config = WebConfigurationManager.OpenWebConfiguration( Request.ApplicationPath); //取得web.config設定檔 config.ConnectionStrings.ConnectionStrings.Add(new ConnectionStringSettings("pubsConnectionString", "server=.;database=pubs;integrated security=true")); //新增資料到加密區段 config.Save(); //將加密後的結果存回web.config設定檔 ======================= end ======================== ================== box 程式9 ============== Configuration config = WebConfigurationManager.OpenWebConfiguration( Request.ApplicationPath); //取得web.config設定檔 ConfigurationSection section = config.Sections["connectionStrings"]; //取得被加密的區段名稱 section.SectionInformation.UnprotectSection(); //對區段的內容解密 config.Save(); //將解密後的結果存回web.config設定檔 ===================== end ================= =================== box 程式10 ================= ==================== end ========================= ================== box 程式11 ================== string[] UserNames = txtUserName.Text.Split(' '); //取出在txtUserName欄位中輸入的以空格分隔的多個使用者名稱 Roles.AddUsersToRole(UserNames, DropDownList1.Text); //將取得的使用者名稱加入到指定的角色中 ======================= end ==================== ==================== box 程式12 ==================== string[] UserNames = Roles.GetUsersInRole("Manager"); //取出名稱為Manager的角色的所有成員 foreach (string s in UserNames) //取出所有的成員名稱 {  lbManager.Items.Add(s); //將取出的成員名稱加入到ListBox控制項中 } ======================= end ======================== ====================== box 程式碼13 ====================== if (User.IsInRole("Manager")) //判斷網頁使用者的角色是否是名稱為Manager角色的成員 { btnAdd.Enabled = true; //啟用btnAdd按鍵 } else { btnAdd.Enabled = false; //禁用btnAdd按鍵 } ============================== end ========================