Getting current windows user and groups

Discussion in 'ASP .Net' started by Mark, Feb 3, 2004.

  1. Mark

    Mark Guest

    hey,
    i'm trying to get the current windows user and the groups they are in.
    Intergrated windows auth on and annoymous access turned off on IIS.

    However when trying to compile the following code VS.net doesn't like
    the User.IsInRole("domain"); With the error "type or namspace for User
    not found".
    I can't work out which reference i'm missing!

    Basically the idea is to create a auth component that is called for
    any authentication/authorization purposes.

    Thanks for any help,



    using System;
    using System.ComponentModel;
    using System.Collections;
    using System.Diagnostics;
    using System.Security.Principal;

    //Upon creation of this object set all varables to the current user
    CurrentUser = WindowsIdentity.GetCurrent().Name;
    isWinAuth = WindowsIdentity.GetCurrent().IsAuthenticated;

    //check if the user is in any of these groups
    //not the best, but usable

    if (User.IsInRole("blah")) UserGroups.Add("blah");
    if (User.IsInRole("blah")) UserGroups.Add("blah");
    if (User.IsInRole("blah")) UserGroups.Add("blah");
     
    Mark, Feb 3, 2004
    #1
    1. Advertising

  2. hi,
    i think u r missing
    using System.Security;




    --
    Thanks and Regards,

    Amit Agarwal
    Software Programmer(.NET)
    "Mark" <> wrote in message
    news:...
    > hey,
    > i'm trying to get the current windows user and the groups they are in.
    > Intergrated windows auth on and annoymous access turned off on IIS.
    >
    > However when trying to compile the following code VS.net doesn't like
    > the User.IsInRole("domain"); With the error "type or namspace for User
    > not found".
    > I can't work out which reference i'm missing!
    >
    > Basically the idea is to create a auth component that is called for
    > any authentication/authorization purposes.
    >
    > Thanks for any help,
    >
    >
    >
    > using System;
    > using System.ComponentModel;
    > using System.Collections;
    > using System.Diagnostics;
    > using System.Security.Principal;
    >
    > //Upon creation of this object set all varables to the current user
    > CurrentUser = WindowsIdentity.GetCurrent().Name;
    > isWinAuth = WindowsIdentity.GetCurrent().IsAuthenticated;
    >
    > //check if the user is in any of these groups
    > //not the best, but usable
    >
    > if (User.IsInRole("blah")) UserGroups.Add("blah");
    > if (User.IsInRole("blah")) UserGroups.Add("blah");
    > if (User.IsInRole("blah")) UserGroups.Add("blah");



    ---
    Outgoing mail is certified Virus Free.
    Checked by AVG anti-virus system (http://www.grisoft.com).
    Version: 6.0.576 / Virus Database: 365 - Release Date: 1/30/2004
     
    .NET Follower, Feb 3, 2004
    #2
    1. Advertising

  3. Mark

    Mark Guest

    Nope, System.Security still causes the same errors.

    Is there another way to get/check which windows groups the user is in?

    thanks


    ".NET Follower" <> wrote in message news:<>...
    > hi,
    > i think u r missing
    > using System.Security;
    >
    >
    >
    >
    > --
    > Thanks and Regards,
    >
    > Amit Agarwal
    > Software Programmer(.NET)
    > "Mark" <> wrote in message
    > news:...
    > > hey,
    > > i'm trying to get the current windows user and the groups they are in.
    > > Intergrated windows auth on and annoymous access turned off on IIS.
    > >
    > > However when trying to compile the following code VS.net doesn't like
    > > the User.IsInRole("domain"); With the error "type or namspace for User
    > > not found".
    > > I can't work out which reference i'm missing!
    > >
    > > Basically the idea is to create a auth component that is called for
    > > any authentication/authorization purposes.
    > >
    > > Thanks for any help,
    > >
    > >
    > >
    > > using System;
    > > using System.ComponentModel;
    > > using System.Collections;
    > > using System.Diagnostics;
    > > using System.Security.Principal;
    > >
    > > //Upon creation of this object set all varables to the current user
    > > CurrentUser = WindowsIdentity.GetCurrent().Name;
    > > isWinAuth = WindowsIdentity.GetCurrent().IsAuthenticated;
    > >
    > > //check if the user is in any of these groups
    > > //not the best, but usable
    > >
    > > if (User.IsInRole("blah")) UserGroups.Add("blah");
    > > if (User.IsInRole("blah")) UserGroups.Add("blah");
    > > if (User.IsInRole("blah")) UserGroups.Add("blah");

    >
    >
    > ---
    > Outgoing mail is certified Virus Free.
    > Checked by AVG anti-virus system (http://www.grisoft.com).
    > Version: 6.0.576 / Virus Database: 365 - Release Date: 1/30/2004
     
    Mark, Feb 3, 2004
    #3
  4. Mark

    Tommy Guest

    Not sure if this is related to your problem, but I do know that in
    some situation, the WindowsIdentity object will return a blank name.
    To resolve this, you can change the authorization section in
    Web.Config as follow:

    <authorization>
    <deny users="?" /> <!-- Allow all users -->
    <allow users="*" />
    <!-- <allow users="[comma separated list of users]"
    roles="[comma separated list of roles]"/>
    <deny users="[comma separated list of users]"
    roles="[comma separated list of roles]"/>
    -->
    </authorization>

    See if this helps your situation.

    Tommy,

    (Mark) wrote in message news:<>...
    > hey,
    > i'm trying to get the current windows user and the groups they are in.
    > Intergrated windows auth on and annoymous access turned off on IIS.
    >
    > However when trying to compile the following code VS.net doesn't like
    > the User.IsInRole("domain"); With the error "type or namspace for User
    > not found".
    > I can't work out which reference i'm missing!
    >
    > Basically the idea is to create a auth component that is called for
    > any authentication/authorization purposes.
    >
    > Thanks for any help,
    >
    >
    >
    > using System;
    > using System.ComponentModel;
    > using System.Collections;
    > using System.Diagnostics;
    > using System.Security.Principal;
    >
    > //Upon creation of this object set all varables to the current user
    > CurrentUser = WindowsIdentity.GetCurrent().Name;
    > isWinAuth = WindowsIdentity.GetCurrent().IsAuthenticated;
    >
    > //check if the user is in any of these groups
    > //not the best, but usable
    >
    > if (User.IsInRole("blah")) UserGroups.Add("blah");
    > if (User.IsInRole("blah")) UserGroups.Add("blah");
    > if (User.IsInRole("blah")) UserGroups.Add("blah");
     
    Tommy, Feb 4, 2004
    #4
  5. Mark

    Mark Guest

    Nah it just won't even compile, let alone return a blank user. I think
    User.Identity.Name; WindowsIdentity.GetCurrent().Name; must have to be
    called from the direct page and not from a component or something.
    thanks tho,

    (Tommy) wrote in message news:<>...
    > Not sure if this is related to your problem, but I do know that in
    > some situation, the WindowsIdentity object will return a blank name.
    > To resolve this, you can change the authorization section in
    > Web.Config as follow:
    >
    > <authorization>
    > <deny users="?" /> <!-- Allow all users -->
    > <allow users="*" />
    > <!-- <allow users="[comma separated list of users]"
    > roles="[comma separated list of roles]"/>
    > <deny users="[comma separated list of users]"
    > roles="[comma separated list of roles]"/>
    > -->
    > </authorization>
    >
    > See if this helps your situation.
    >
    > Tommy,
    >
    > (Mark) wrote in message news:<>...
    > > hey,
    > > i'm trying to get the current windows user and the groups they are in.
    > > Intergrated windows auth on and annoymous access turned off on IIS.
    > >
    > > However when trying to compile the following code VS.net doesn't like
    > > the User.IsInRole("domain"); With the error "type or namspace for User
    > > not found".
    > > I can't work out which reference i'm missing!
    > >
    > > Basically the idea is to create a auth component that is called for
    > > any authentication/authorization purposes.
    > >
    > > Thanks for any help,
    > >
    > >
    > >
    > > using System;
    > > using System.ComponentModel;
    > > using System.Collections;
    > > using System.Diagnostics;
    > > using System.Security.Principal;
    > >
    > > //Upon creation of this object set all varables to the current user
    > > CurrentUser = WindowsIdentity.GetCurrent().Name;
    > > isWinAuth = WindowsIdentity.GetCurrent().IsAuthenticated;
    > >
    > > //check if the user is in any of these groups
    > > //not the best, but usable
    > >
    > > if (User.IsInRole("blah")) UserGroups.Add("blah");
    > > if (User.IsInRole("blah")) UserGroups.Add("blah");
    > > if (User.IsInRole("blah")) UserGroups.Add("blah");
     
    Mark, Feb 5, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Petra Hübner
    Replies:
    0
    Views:
    449
    Petra Hübner
    Feb 16, 2004
  2. Nick
    Replies:
    4
    Views:
    8,597
    Greg Burns
    Jul 22, 2004
  3. anonymous
    Replies:
    1
    Views:
    4,601
    Francisco Padron
    May 8, 2005
  4. Replies:
    3
    Views:
    365
    Peter Hansen
    Jun 10, 2005
  5. mpnordland
    Replies:
    24
    Views:
    895
Loading...

Share This Page