473,378 Members | 1,531 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Identifying user in Windows group

Hello,

I am using Visual SourceSafe to work on a project in a team of three.

I have created a Windows group caleed "Application_MO" on my machine and
added my Windows login to it.

However, when I run the code below, the answer is always "KO" i.e. I am not
identified as belonging to the "Application_MO" group. What could be the
problem?

If HttpContext.Current.User.IsInRole("Application_MO" ) Then
Response.Write("User exists")

Else

Response.Write("<font color=red>KO<font color>")

Thanks in advance

TJ
Nov 19 '05 #1
9 1546
"Tapi" <t.******@free.fr> wrote in message
news:eX******************@TK2MSFTNGP12.phx.gbl...
If HttpContext.Current.User.IsInRole("Application_MO" ) Then
Response.Write("User exists")

Else

Response.Write("<font color=red>KO<font color>")


Do this:

Response.Write(HttpContext.Current.User.Identity.N ame)

so that you know who ASP.NET thinks the current user is...
Nov 19 '05 #2
I have done that and it correctly identifies me.

However, the problem still remains of finding out if I belong to the said
group in Windows.

Help!

"Mark Rae" <ma**@mark-N-O-S-P-A-M-rae.co.uk> wrote in message
news:ec**************@TK2MSFTNGP12.phx.gbl...
"Tapi" <t.******@free.fr> wrote in message
news:eX******************@TK2MSFTNGP12.phx.gbl...
If HttpContext.Current.User.IsInRole("Application_MO" ) Then
Response.Write("User exists")

Else

Response.Write("<font color=red>KO<font color>")


Do this:

Response.Write(HttpContext.Current.User.Identity.N ame)

so that you know who ASP.NET thinks the current user is...

Nov 19 '05 #3
"Tapi" <t.******@free.fr> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I have done that and it correctly identifies me.
OK.
However, the problem still remains of finding out if I belong to the said
group in Windows.


Might it be simply that the ASPNET account doesn't have sufficient
permissions to query the ActiveDirectory...?

Below is an extremely simple but very effective C# method I use for
determining whether a given user is in a given group - it shouldn't be too
difficult to convert it into VB.NET - you'll need to reference the
System.DirectoryServices namespace...

public static bool IsUserInGroup(string pstrDomain, string pstrUser, string
pstrGroup)
{
DirectoryEntry objADEntry = null;
DirectoryEntry objUser = null;
DirectoryEntry objGroup = null;

try
{
objADEntry = new DirectoryEntry("WinNT://" + pstrDomain + ",domain");
objUser = objADEntry.Children.Find(pstrUser, "user");
objGroup = objADEntry.Children.Find(pstrGroup, "group");
return (bool) objGroup.Invoke("IsMember", new object[]
{objUser.Path.ToString()});
}
catch (Exception)
{
throw;
}
finally
{
if (objGroup != null)
{
objGroup.Close();
objGroup.Dispose();
objGroup = null;
}
if (objUser != null)
{
objUser.Close();
objUser.Dispose();
objUser = null;
}
if (objADEntry != null)
{
objADEntry.Close();
objADEntry.Dispose();
objADEntry = null;
}
}
}
Nov 19 '05 #4
Thanks, I will trying that after the "translation" to VB.
"Mark Rae" <ma**@mark-N-O-S-P-A-M-rae.co.uk> wrote in message
news:ON**************@tk2msftngp13.phx.gbl...
"Tapi" <t.******@free.fr> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I have done that and it correctly identifies me.
OK.
However, the problem still remains of finding out if I belong to the said group in Windows.


Might it be simply that the ASPNET account doesn't have sufficient
permissions to query the ActiveDirectory...?

Below is an extremely simple but very effective C# method I use for
determining whether a given user is in a given group - it shouldn't be too
difficult to convert it into VB.NET - you'll need to reference the
System.DirectoryServices namespace...

public static bool IsUserInGroup(string pstrDomain, string pstrUser,

string pstrGroup)
{
DirectoryEntry objADEntry = null;
DirectoryEntry objUser = null;
DirectoryEntry objGroup = null;

try
{
objADEntry = new DirectoryEntry("WinNT://" + pstrDomain + ",domain");
objUser = objADEntry.Children.Find(pstrUser, "user");
objGroup = objADEntry.Children.Find(pstrGroup, "group");
return (bool) objGroup.Invoke("IsMember", new object[]
{objUser.Path.ToString()});
}
catch (Exception)
{
throw;
}
finally
{
if (objGroup != null)
{
objGroup.Close();
objGroup.Dispose();
objGroup = null;
}
if (objUser != null)
{
objUser.Close();
objUser.Dispose();
objUser = null;
}
if (objADEntry != null)
{
objADEntry.Close();
objADEntry.Dispose();
objADEntry = null;
}
}
}

Nov 19 '05 #5
Public Shared Function IsUserInGroup(pstrDomain As String, pstrUser As String, pstrGroup
As String) As Boolean

Dim objADEntry As DirectoryEntry = Nothing
Dim objUser As DirectoryEntry = Nothing
Dim objGroup As DirectoryEntry = Nothing

Try
objADEntry = New DirectoryEntry("WinNT://" + pstrDomain + ",domain")
objUser = objADEntry.Children.Find(pstrUser, "user")
objGroup = objADEntry.Children.Find(pstrGroup, "group")
Return CBool(objGroup.Invoke("IsMember", New Object() {objUser.Path.ToString()}))
Catch Else
Throw
Finally
If Not (objGroup Is Nothing) Then
objGroup.Close()
objGroup.Dispose()
objGroup = Nothing
End If
If Not (objUser Is Nothing) Then
objUser.Close()
objUser.Dispose()
objUser = Nothing
End If
If Not (objADEntry Is Nothing) Then
objADEntry.Close()
objADEntry.Dispose()
objADEntry = Nothing
End If
End Try
End Function 'IsUserInGroup

Courtesy of "C# To VB .NET Source Code Converter":
http://www.eggheadcafe.com/articles/...converter.aspx

It took about 3 seconds to get that code converted... ;-)

You might want to check it for errors,
but at least the grunt work is done for you.


Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
Foros de ASP.NET en Español : http://asp.net.do/foros/
======================================
"Tapi" <t.******@free.fr> wrote in message news:Oe**************@TK2MSFTNGP14.phx.gbl...
Thanks, I will trying that after the "translation" to VB.
"Mark Rae" <ma**@mark-N-O-S-P-A-M-rae.co.uk> wrote in message
news:ON**************@tk2msftngp13.phx.gbl...
"Tapi" <t.******@free.fr> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
>I have done that and it correctly identifies me.


OK.
> However, the problem still remains of finding out if I belong to the said > group in Windows.


Might it be simply that the ASPNET account doesn't have sufficient
permissions to query the ActiveDirectory...?

Below is an extremely simple but very effective C# method I use for
determining whether a given user is in a given group - it shouldn't be too
difficult to convert it into VB.NET - you'll need to reference the
System.DirectoryServices namespace...

public static bool IsUserInGroup(string pstrDomain, string pstrUser,

string
pstrGroup)
{
DirectoryEntry objADEntry = null;
DirectoryEntry objUser = null;
DirectoryEntry objGroup = null;

try
{
objADEntry = new DirectoryEntry("WinNT://" + pstrDomain + ",domain");
objUser = objADEntry.Children.Find(pstrUser, "user");
objGroup = objADEntry.Children.Find(pstrGroup, "group");
return (bool) objGroup.Invoke("IsMember", new object[]
{objUser.Path.ToString()});
}
catch (Exception)
{
throw;
}
finally
{
if (objGroup != null)
{
objGroup.Close();
objGroup.Dispose();
objGroup = null;
}
if (objUser != null)
{
objUser.Close();
objUser.Dispose();
objUser = null;
}
if (objADEntry != null)
{
objADEntry.Close();
objADEntry.Dispose();
objADEntry = null;
}
}
}


Nov 19 '05 #6
"Juan T. Llibre" <no***********@nowhere.com> wrote in message
news:u0**************@TK2MSFTNGP10.phx.gbl...
It took about 3 seconds to get that code converted... ;-)


That's pretty impressive!
Nov 19 '05 #7
And that includes internet latency, too!

;-)

I suspect the actual processing time is well under 1/10 second.

Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
Foros de ASP.NET en Español : http://asp.net.do/foros/
======================================
"Mark Rae" <ma**@mark-N-O-S-P-A-M-rae.co.uk> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
"Juan T. Llibre" <no***********@nowhere.com> wrote in message
news:u0**************@TK2MSFTNGP10.phx.gbl...
It took about 3 seconds to get that code converted... ;-)


That's pretty impressive!

Nov 19 '05 #8
"Juan T. Llibre" <no***********@nowhere.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
I suspect the actual processing time is well under 1/10 second.


It certainly seems like a good utility, so long you remove the XML comments
first...
Nov 19 '05 #9
Thanks a lot for the conversion.

However, I have tried my code on an XP workstation and it works. I am using
a Windows 2000 workstation. Could it be that I need to install something
(Service pack/:NET addin...) that will enable the code to work?

I have service pack 4 installed.
"Juan T. Llibre" <no***********@nowhere.com> wrote in message
news:u0**************@TK2MSFTNGP10.phx.gbl...
Public Shared Function IsUserInGroup(pstrDomain As String, pstrUser As String, pstrGroup As String) As Boolean

Dim objADEntry As DirectoryEntry = Nothing
Dim objUser As DirectoryEntry = Nothing
Dim objGroup As DirectoryEntry = Nothing

Try
objADEntry = New DirectoryEntry("WinNT://" + pstrDomain + ",domain")
objUser = objADEntry.Children.Find(pstrUser, "user")
objGroup = objADEntry.Children.Find(pstrGroup, "group")
Return CBool(objGroup.Invoke("IsMember", New Object() {objUser.Path.ToString()})) Catch Else
Throw
Finally
If Not (objGroup Is Nothing) Then
objGroup.Close()
objGroup.Dispose()
objGroup = Nothing
End If
If Not (objUser Is Nothing) Then
objUser.Close()
objUser.Dispose()
objUser = Nothing
End If
If Not (objADEntry Is Nothing) Then
objADEntry.Close()
objADEntry.Dispose()
objADEntry = Nothing
End If
End Try
End Function 'IsUserInGroup

Courtesy of "C# To VB .NET Source Code Converter":
http://www.eggheadcafe.com/articles/...converter.aspx

It took about 3 seconds to get that code converted... ;-)

You might want to check it for errors,
but at least the grunt work is done for you.


Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
Foros de ASP.NET en Español : http://asp.net.do/foros/
======================================
"Tapi" <t.******@free.fr> wrote in message

news:Oe**************@TK2MSFTNGP14.phx.gbl...
Thanks, I will trying that after the "translation" to VB.


"Mark Rae" <ma**@mark-N-O-S-P-A-M-rae.co.uk> wrote in message
news:ON**************@tk2msftngp13.phx.gbl...
"Tapi" <t.******@free.fr> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...

>I have done that and it correctly identifies me.

OK.

> However, the problem still remains of finding out if I belong to the

said
> group in Windows.

Might it be simply that the ASPNET account doesn't have sufficient
permissions to query the ActiveDirectory...?

Below is an extremely simple but very effective C# method I use for
determining whether a given user is in a given group - it shouldn't be too difficult to convert it into VB.NET - you'll need to reference the
System.DirectoryServices namespace...

public static bool IsUserInGroup(string pstrDomain, string pstrUser,

string
pstrGroup)
{
DirectoryEntry objADEntry = null;
DirectoryEntry objUser = null;
DirectoryEntry objGroup = null;

try
{
objADEntry = new DirectoryEntry("WinNT://" + pstrDomain + ",domain");
objUser = objADEntry.Children.Find(pstrUser, "user");
objGroup = objADEntry.Children.Find(pstrGroup, "group");
return (bool) objGroup.Invoke("IsMember", new object[]
{objUser.Path.ToString()});
}
catch (Exception)
{
throw;
}
finally
{
if (objGroup != null)
{
objGroup.Close();
objGroup.Dispose();
objGroup = null;
}
if (objUser != null)
{
objUser.Close();
objUser.Dispose();
objUser = null;
}
if (objADEntry != null)
{
objADEntry.Close();
objADEntry.Dispose();
objADEntry = null;
}
}
}



Nov 19 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: David | last post by:
I know that identifying the user IP address with HTTP_SERVER_VARS; is reliant on the browser agent but I have stumpled upon the following code which I have tried to understand but failed! ...
2
by: Tom Loach | last post by:
Our system administrator set up an NT server group in order to allow our users to login to our application via https to our sql server. The group appears as a User in SQL Server when you look at...
2
by: Technical Group | last post by:
Friends, Can anybody help me out by sending a piece of C# code showing how to add an active directory user to a particular user group? If the group does not exist, then create it. Thanks in...
7
by: Don Riesbeck Jr. | last post by:
I'm working on an application (OEM) using C# that utilizes input from a keyboard, and USB Barcode Scanner. The scanner is a HID Keyboard device, and input from it is sent to the system as if it...
3
by: Christopher Weaver | last post by:
I want to set a value in a specific field in the current row of a DataSet. This seems like the most basic thing to do but I can't find the syntax for identifying the current row. IOW, I can do...
3
by: Jiho Han | last post by:
Should ASPNET user belong to the local Users group? I may have made some changes that affected my workstation setup and I am experiencing some unexpected behaviors. For example, I have my IIS...
6
by: Tapi | last post by:
Hello, I can easily get the Windows login of the current user on my machine by using: User_login = HttpContext.Current.User.Identity.Name() However once, I copy the aspx and...
4
by: James | last post by:
I have a VB windows forms application that accesses a Microsoft Access database that has been secured using user-level security. The application is being deployed using No-Touch deployment. The...
8
by: Mark White | last post by:
Hey everyone I'm having a great deal of problems finding this information through google and yahoo, so I turn to you on this. I have a Windows app running on XP. I am able to caputre the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.