Go Back   Velocity Reviews > Newsgroups > ASP Net
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

ASP Net - Getting current windows user and groups

 
Thread Tools Search this Thread
Old 02-03-2004, 05:17 AM   #1
Default 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");


Mark
  Reply With Quote
Old 02-03-2004, 06:05 AM   #2
.NET Follower
 
Posts: n/a
Default Re: Getting current windows user and groups
hi,
i think u r missing
using System.Security;




--
Thanks and Regards,

Amit Agarwal
Software Programmer(.NET)
"Mark" <> wrote in message
news: 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




.NET Follower
  Reply With Quote
Old 02-03-2004, 11:44 PM   #3
Mark
 
Posts: n/a
Default Re: Getting current windows user and groups
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" <amitagarwal-> 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: 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



Mark
  Reply With Quote
Old 02-04-2004, 01:03 PM   #4
Tommy
 
Posts: n/a
Default Re: Getting current windows user and groups
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:<. 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");



Tommy
  Reply With Quote
Old 02-05-2004, 04:45 AM   #5
Mark
 
Posts: n/a
Default Re: Getting current windows user and groups
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:<. 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,
>
> (Mark) wrote in message news:<. 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");



Mark
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Computer Security aldrich.chappel.com.use@gmail.com A+ Certification 0 11-27-2007 02:11 AM
Google Groups Killfile - No more annoying posts! Jordan DVD Video 2 09-01-2007 11:26 PM
Re: Problem with windows 2000 Tmack A+ Certification 0 08-10-2005 08:22 PM
Info needed urls etc user groups fof 169 hdtv uriah@nospam.net DVD Video 0 04-18-2005 10:30 PM
New user groups Joe Hard Drive DVD Video 0 06-07-2004 01:09 AM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46