Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: Windows Authentication


Message #1 by "Frank Tichy" <tichy@s...> on Mon, 15 Oct 2001 13:49:56 +0200
Hi all,



I'd like to protect my c#-based web-application with windows authentication.

In order to achieve this I'd like to read the username and the

windows-role(administrator, User, Guest etc.) of the user. In the IIS I use

Basic Authentication (due to browser issues). Knowing the user's role I

could present the content according to the user's rights. So far I've only

managed to get the user-name and the authenication-type but not the

users-role. Can anyone give me a hint how to pick out the user-role?



Here's the source:



<%@ Page language="c#" debug="True" %>

<% @ Import Namespace = System.Security.Principal %>

<% @ Import Namespace = System.Threading %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >



<html>



  <script language="C#" runat=server>



    void Page_Load(Object Src, EventArgs E )

    {

      AuthUser.Text = User.Identity.Name;

      AuthType.Text = User.Identity.AuthenticationType;

      AuthTrueFalse.Text = User.Identity.IsAuthenticated.ToString();

      //AuthGuest.Text = StrGast;

    }



  </script>



  <body>



    <h3><font face="Verdana">Windows Authentication</font></h3>



    <table Width="700" rules="all" bordercolor="Black"

style="background-color:#ccccff;bordercolor:black;font-family:Verdana;font-s

ize:8pt;border-collapse:collapse;">

      <tr>

        <td>Benutzer:</td>

        <td><asp:label id=AuthUser runat=server/>

      </tr>

      <tr>

        <td>Authentication Typ:</td>

        <td><asp:label id=AuthType runat=server/>

      </tr>

      <tr>

        <td>Authenticated:</td>

        <td><asp:label id="AuthTrueFalse" runat=server/>

      </tr>

      <tr>

        <td>Authentication Rolle:</td>

        <td><asp:label id="AuthGuest" runat=server/>

      </tr>

    </table>



  </body>



</html>



Thanks in advance



Kind regards

Frank Tichy

Web7

Message #2 by "Ivan Pavlovic" <ipavlovi@y...> on Thu, 18 Oct 2001 08:33:35 +0200
You can use something like



txtGroup.Text = Convert.ToString(User.IsInRole("Administrators"))



but you probably know that. I don't see any reason why you want to read

user's group name from code.



You can just ask IsInRole("XYZ") and than do whatever you want...







Ivan Pavlovic




  Return to Index