ASP.NET Tutorial/Authentication Authorization/WindowsPrincipal

Материал из .Net Framework эксперт
Перейти к: навигация, поиск

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>