469,923 Members | 1,683 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,923 developers. It's quick & easy.

Getting current windows user and groups

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");
Nov 18 '05 #1
4 2949
hi,
i think u r missing
using System.Security;


--
Thanks and Regards,

Amit Agarwal
Software Programmer(.NET)
"Mark" <ma***********@eq.edu.au> wrote in message
news:44**************************@posting.google.c om...
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
Nov 18 '05 #2
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" <am*************@SoftHome.net> wrote in message news:<uJ**************@TK2MSFTNGP10.phx.gbl>...
hi,
i think u r missing
using System.Security;


--
Thanks and Regards,

Amit Agarwal
Software Programmer(.NET)
"Mark" <ma***********@eq.edu.au> wrote in message
news:44**************************@posting.google.c om...
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

Nov 18 '05 #3
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,

ma***********@eq.edu.au (Mark) wrote in message news:<44**************************@posting.google. com>...
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");

Nov 18 '05 #4
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,

We**********@Hotmail.com (Tommy) wrote in message news:<a8**************************@posting.google. com>...
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,

ma***********@eq.edu.au (Mark) wrote in message news:<44**************************@posting.google. com>...
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");

Nov 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Nick | last post: by
4 posts views Thread by Vik | last post: by
5 posts views Thread by henrycortezwu | last post: by
8 posts views Thread by Mark White | last post: by
13 posts views Thread by Steve Enzer | last post: by
4 posts views Thread by Odd Bjørn Andersen | last post: by
3 posts views Thread by tshad | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.