i have a web app that is using active directory for authentication...so instead of setting up my roles in the config file like I normally would, they were set up in the security groups of the active directory. How can I programitcally access these security
groups? i would normally use something like if user.isinroles("admin")...can I still use isInRoles and if so what should I use as my argument, i tried putting in the security group but that didnt seem to work? also would that be the best way of doing it
or is there another way to access the security groups? thanks in advance.
I'm having the same issues on the same task as you did, but have not resolved it yet. Would appreciate advise on what is incorrect in the following sample code? The result I get is always that the panel is not visible, even though the authenticated user
is a member of 'Domain\ADGroup'.
If I can at least confirm the code 'should' work, that would be a help.
Page.aspx.vb
If HttpContext.Current.User.IsInRole("Domain\ADGroup") Then
Panel1.Visible = True
Label1.Text = "Hello"
Else
Panel1.Visible = False
Label1.Text = "Not working"
End If
d384
Member
31 Points
22 Posts
roles and active directory
Feb 17, 2012 07:07 PM|LINK
i have a web app that is using active directory for authentication...so instead of setting up my roles in the config file like I normally would, they were set up in the security groups of the active directory. How can I programitcally access these security groups? i would normally use something like if user.isinroles("admin")...can I still use isInRoles and if so what should I use as my argument, i tried putting in the security group but that didnt seem to work? also would that be the best way of doing it or is there another way to access the security groups? thanks in advance.
ryanbesko
Contributor
3607 Points
630 Posts
Re: roles and active directory
Feb 17, 2012 07:19 PM|LINK
User.IsInRole("role name") works with Active Directory, too. Must have some problem with your role name.
d384
Member
31 Points
22 Posts
Re: roles and active directory
Feb 17, 2012 07:27 PM|LINK
there aren't any roles setup in the AD just security groups...so are you saying that they are one and the same? or do roles need to be set up in AD?
ryanbesko
Contributor
3607 Points
630 Posts
Re: roles and active directory
Feb 17, 2012 07:28 PM|LINK
They are one in the same.
d384
Member
31 Points
22 Posts
Re: roles and active directory
Feb 17, 2012 08:27 PM|LINK
ok thanks, once I get a chance ill give it a shot and see what happens...will let you know.
d384
Member
31 Points
22 Posts
Re: roles and active directory
Feb 21, 2012 01:07 PM|LINK
got it to work..thanks.
ShaggyDogg
Member
6 Points
10 Posts
Re: roles and active directory
May 30, 2012 08:43 AM|LINK
Hi d384.
I'm having the same issues on the same task as you did, but have not resolved it yet. Would appreciate advise on what is incorrect in the following sample code? The result I get is always that the panel is not visible, even though the authenticated user is a member of 'Domain\ADGroup'.
If I can at least confirm the code 'should' work, that would be a help.
Page.aspx.vb
If HttpContext.Current.User.IsInRole("Domain\ADGroup") Then Panel1.Visible = True Label1.Text = "Hello" Else Panel1.Visible = False Label1.Text = "Not working" End IfWeb.config
<connectionStrings> <add name="ADService" connectionString="LDAP://Domain.internal"/> <add name="ApplicationServices" connectionString="Data Source=Server;Initial Catalog=ASPNETDB;Persist Security Info="blah blah" providerName="System.Data.SqlClient"/> </connectionStrings> <authentication mode="Windows"/> <identity impersonate="true"/> <membership defaultProvider="AspNetActiveDirectoryMembershipProvider"> <providers> <clear/> <add name="AspNetActiveDirectoryMembershipProvider" enableSearchMethods="true" type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="ADService" attributeMapUsername="sAMAccountName"/> </providers> </membership> <profile> <providers> <clear/> <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/> </providers> </profile> <roleManager enabled="true"> <providers> <clear/> <add name="WindowsProvider" type="System.Web.Security.WindowsTokenRoleProvider"/> <add connectionStringName="ApplicationServices" applicationName="/" name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider"/> <add applicationName="/" name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider"/> </providers> </roleManager>Many thanks in advance..
ShaggyDogg
Member
6 Points
10 Posts
Re: roles and active directory
May 31, 2012 08:30 AM|LINK
Don't worry replying - got it working too.
This one line of code (within the system.web element) sorted it instead of what I had
Plus this msdn article showing the same syntax was very useful:
http://msdn.microsoft.com/en-us/library/ff647401.aspx