1)母版页代码
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 <%@ Master Language="C#" %> 2 3 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 4 <script runat="server"> 5 protected override void OnLoad(EventArgs e) 6 { 7 base.OnLoad(e); 8 this.menuAdminSystem.Visible = Roles.IsUserInRole("管理员"); 9 } 10 public void Page_Load(object sender, EventArgs e) 11 { 12 if (!Page.IsPostBack) 13 { 14 this.ShowUserRoles(); 15 } 16 } 17 private void ShowUserRoles() 18 { 19 string[] roles = Roles.GetRolesForUser(); 20 for (int i = 0; i < roles.Length; i++) 21 { 22 LiteralRoles.Text += roles[i]; 23 if (i != roles.Length - 1) 24 { 25 LiteralRoles.Text += ","; 26 } 27 } 28 } 29 </script> 30 <html xmlns="http://www.w3.org/1999/xhtml"> 31 <head runat="server"> 32 <title></title> 33 <link href="css/StyleSheet.css" rel="stylesheet" type="text/css" /> 34 <script src="js/JScript.js" type="text/javascript"></script> 35 <script src="js/tableJScript.js" type="text/javascript"></script> 36 <asp:ContentPlaceHolder ID="head" runat="server"> 37 </asp:ContentPlaceHolder> 38 </head> 39 <body> 40 <form id="form1" runat="server"> 41 <div id="header"> 42 <table width="100%" border="0" cellpadding="0" cellspacing="0"> 43 <tr> 44 <td width="178" height="60" align="center" style="background-image: url(css/images/top_logo.jpg); 45 background-repeat: no-repeat;"> 46 </td> 47 <td align="center" style="background: url(css/images/top_bg.jpg) no-repeat"> 48 <table cellspacing="0" cellpadding="0" border="0" width="100%" height="33"> 49 <tbody> 50 <tr> 51 <td width="400" align="left"> 52 <img onclick="switchBar(this)" height="15" alt="关闭左边管理菜单" src="css/images/on-of.gif" 53 style="cursor: hand;" width="15" border="0" /> 54 <asp:LoginName ID="LoginName1" runat="server" FormatString="欢迎您:{0}" /> 55 ,您是:<asp:Literal ID="LiteralRoles" runat="server"></asp:Literal> 56 </td> 57 </tr> 58 </tbody> 59 </table> 60 <table height="26" border="0" align="left" cellpadding="0" cellspacing="0" class="subbg" 61 name="t1"> 62 <tbody> 63 <tr align="middle"> 64 <td width="71" height="26" align="center" valign="middle" background="css/images/top_tt_bg.gif"> 65 <a href="Default.aspx" class="STYLE2">管理首页</a> 66 </td> 67 <td align="center" class="topbar"> 68 <span class="STYLE2"></span> 69 </td> 70 <td width="71" align="center" valign="middle" background="css/images/top_tt_bg.gif"> 71 <asp:LoginStatus ID="LoginStatus1" runat="server" LogoutText="退出登录" /> 72 </td> 73 </tr> 74 </tbody> 75 </table> 76 </td> 77 </tr> 78 <tr height="6"> 79 <td bgcolor="#1F3A65" background="css/images/top_bg2.jpg"> 80 </td> 81 </tr> 82 </table> 83 </div> 84 <div style="width: 1004px;"> 85 <div id="left"> 86 <table width="98%" border="0" cellpadding="0" cellspacing="0" background="css/images/tablemde.jpg"> 87 <asp:Panel runat="server" ID="menuAdminSystem"> 88 <tr> 89 <td height="5" background="css/images/tableline_top.jpg" bgcolor="#16ACFF"> 90 </td> 91 </tr> 92 <tr> 93 <td> 94 <table width="97%" border="0" align="right" cellpadding="0" cellspacing="0" class="leftframetable"> 95 <tbody> 96 <tr> 97 <td height="25" style="background: url(css/images/left_tt.gif) no-repeat"> 98 <table width="100%" border="0" cellspacing="0" cellpadding="0"> 99 <tr> 100 <td width="20"> 101 </td> 102 <td class="STYLE1" style="cursor: hand" onclick="showsubmenu(1);" height="25"> 103 系统设置 104 </td> 105 </tr> 106 </table> 107 </td> 108 </tr> 109 <tr> 110 <td> 111 <table id="submenu1" cellspacing="0" cellpadding="0" width="100%" border="0"> 112 <tbody> 113 <tr> 114 <td width="2%"> 115 <img src="css/images/closed.gif"> 116 </td> 117 <td height="23"> 118 <a href="Users.aspx">用户管理</a> | <a href="NewUser.aspx">添加管理用户</a> 119 </td> 120 </tr> 121 122 <tr> 123 <td width="2%"> 124 <img src="css/images/closed.gif"> 125 </td> 126 <td height="23"> 127 <a href="ShipVia.aspx">快递方式</a> | <a href="NewShipVia.aspx">添加快递方式</a> 128 </td> 129 </tr> 130 131 </tbody> 132 </table> 133 </td> 134 </tr> 135 </tbody> 136 </table> 137 </td> 138 </tr> 139 <tr> 140 <td height="5" background="css/images/tableline_bottom.jpg" bgcolor="#9BC2ED"> 141 </td> 142 </tr> 143 </asp:Panel> 144 </table> 145 </div> 146 <div id="right" ondblclick="switchBar(this);"> 147 <table width="100%" border="0" cellspacing="0" cellpadding="0"> 148 <tr> 149 <td height="30" background="images/tab_05.gif"> 150 <table width="100%" border="0" cellspacing="0" cellpadding="0"> 151 <tr> 152 <td width="12" height="30"> 153 <img src="images/tab_03.gif" width="12" height="30" /> 154 </td> 155 <td> 156 <table width="100%" border="0" cellspacing="0" cellpadding="0"> 157 <tr> 158 <td width="46%" valign="middle"> 159 <table width="100%" border="0" cellspacing="0" cellpadding="0"> 160 <tr> 161 <td width="5%"> 162 <div align="center"> 163 <img src="images/tb.gif" width="16" height="16" /></div> 164 </td> 165 <td width="95%" class="STYLE1"> 166 <span class="nav">你当前的位置</span>:<asp:SiteMapPath ID="SiteMapPath1" runat="server"> 167 </asp:SiteMapPath> 168 </td> 169 </tr> 170 </table> 171 </td> 172 <td width="54%" align="right"> 173 <asp:ContentPlaceHolder ID="ContentPlaceHolderOperations" runat="server"> 174 </asp:ContentPlaceHolder> 175 </td> 176 </tr> 177 </table> 178 </td> 179 <td width="16"> 180 <img src="images/tab_07.gif" width="16" height="30" /> 181 </td> 182 </tr> 183 </table> 184 </td> 185 </tr> 186 <tr> 187 <td> 188 <table width="100%" border="0" cellspacing="0" cellpadding="0"> 189 <tr> 190 <td width="8" background="images/tab_12.gif"> 191 192 </td> 193 <td> 194 <asp:ContentPlaceHolder ID="ContentPlaceHolderRightContent" runat="server"> 195 </asp:ContentPlaceHolder> 196 </td> 197 <td width="8" background="images/tab_15.gif"> 198 199 </td> 200 </tr> 201 </table> 202 </td> 203 </tr> 204 <tr> 205 <td height="35" background="images/tab_19.gif"> 206 <table width="100%" border="0" cellspacing="0" cellpadding="0"> 207 <tr> 208 <td width="12" height="35"> 209 <img src="images/tab_18.gif" width="12" height="35" /> 210 </td> 211 <td> 212 <asp:ContentPlaceHolder ID="ContentPlaceHolderPager" runat="server"> 213 </asp:ContentPlaceHolder> 214 </td> 215 <td width="16"> 216 <img src="images/tab_20.gif" width="16" height="35" /> 217 </td> 218 </tr> 219 </table> 220 </td> 221 </tr> 222 </table> 223 </div> 224 </div> 225 </form> 226 </body> 227 </html>