Configure AD Group membership for a web site

This short code example will show you how to configure an ASP.NET website for Windows Authentication, then to allow only members of  a certain group

The <location path="ErrorHandler"> section is intended to allow access to the ErrorHandler folder off the root, to allow for custom error pages. If a user is not allowed, we'll give them a friendly reason why not. 

 

Related Articles

... and you 'll find more on the NET Development Menu

<configuration>
    <system.web>
        <authentication mode="Windows"/>
        <authorization>
            <allow roles="myDomain\myAD_Group"/>
            <deny users="*"/>
        </authorization>
        <roleManager enabled="true" defaultProvider="WindowsProvider">
            <providers>
                <clear/>
                <add name="WindowsProvider" type="System.Web.Security.WindowsTokenRoleProvider"/>
            </providers>
        </roleManager>
    </system.web>
    <location path="ErrorHandler">
        <system.web>
            <authorization>
                <allow users="?"/>
            </authorization>
        </system.web>
    </location>
</configuration>

 

If Roles.IsUserInRole("mydomain\myADGroup") Then
    Me.lblPermissionLevel.Text += "myADGroup | "
End If

Dim s As String() = Roles.GetRolesForUser(HttpContext.Current.User.Identity.Name)

 

 

 



RealWorldCode gives developers practical, real‑world solutions with clean, working code — no fluff, no theory, just answers.
Links
Home
Knowledge Areas
Sitemap
Contact
Et cetera
Privacy Policy
Terms and Conditions
Cookie Preferences