ASP.NET Tutorial/Authentication Authorization/WindowsPrincipal

Материал из .Net Framework эксперт
Версия от 14:57, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

Check Windows Principal

   <source lang="csharp">

<%@Page language="C#" %> <%@Import Namespace="System.Security.Principal" %> <script runat="server"> protected void Page_Load(object o, EventArgs e) {

 WindowsPrincipal principal = (WindowsPrincipal)HttpContext.Current.User;
 if(principal.IsInRole(WindowsBuiltInRole.Administrator)) {
   message.Text = "secret message for Administrators only";
 }

} </script> <form runat="server"> <asp:Label runat="server" id="message" Text="the text everyone can see" />
</form></source>