Entwickler-Ecke

Basistechnologien - Bin ich Admin, Benuter oder Gast, Probleme bei der Bestimmun


Metrik - Mo 23.10.06 17:37
Titel: Bin ich Admin, Benuter oder Gast, Probleme bei der Bestimmun
Hallo
Ich möchte das etwa wie folgt lösen, nur funktioniert das nicht.
Kann mir wer zeigen, was ich falsch mache oder wie man es besser lösen könnte


C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
    private static string getRole()
    {
        string role = String.Empty;

        AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
        WindowsPrincipal windowsPrincipal = (Thread.CurrentPrincipal as WindowsPrincipal);

        try
        {
            switch (windowsPrincipal.IsInRole)
            {
                case WindowsBuiltInRole.Administrator:
                    role = "Admin";
                    break;
                case WindowsBuiltInRole.User:
                    role = "User";
                    break;
            }

        }
        catch (Exception exception)
        {
               Console.WriteLine(exception.Message);
        }    
 
        return role;


Danke
Metrik


Christian S. - Mo 23.10.06 17:50

Ich habe nicht den Eindruck, dass Du Dir auch nur einmal die Doku zu "IsInRole" angesehen hast. Bzw. hätte schon das Lesen der Compilermeldung geholfen.

C#-Quelltext
1:
2:
3:
4:
5:
            if (windowsPrincipal.IsInRole(WindowsBuiltInRole.Administrator))
                return "Admin";

            if (windowsPrincipal.IsInRole(WindowsBuiltInRole.Guest))
                return "Gast";