Use windows authentication with Active directory Lightweight directory services?

StackOverflow https://stackoverflow.com/questions/14335718

  •  15-01-2022
  •  | 
  •  

Domanda

I'm trying to use AD Lightweight Directory Services for user authentication in ASP.net application and dont want to use Forms authentication. Is there any way to authenticate it using windows authentication.

<authentication mode="Windows" />
È stato utile?

Soluzione

You can try this

How To: Use Windows Authentication in ASP.NET 2.0

How To: Use Forms Authentication with Active Directory in ASP.NET 2.0

Edit: This worked for me:

<!-- web.config -->
...
<system.web>
...     
    <compilation debug="true">
        <assemblies>
            <add assembly="System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
        </assemblies>
    </compilation>

    <authentication mode="Windows"/>
    <identity impersonate="true"/>

    <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
        <error statusCode="403" redirect="NoAccess.htm" />
        <error statusCode="404" redirect="FileNotFound.htm" />
    </customErrors>

    <roleManager enabled="true" defaultProvider="AspNetWindowsTokenRoleProvider"/>  

    <authorization>
        <deny users="?"/>
        <allow users="*"/>
    </authorization>
</system.web>
...

and then in code

//page.cs
...
string userName = HttpContext.Current.User.Identity.Name;
...

You should be able to do some custom code with for example DirectoryEntry Class, like Enumerating Users and Groups. Here You can find more about Using Active Directory Lightweight Directory Services.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top