Form authentication
ASP.NET
-
create a windows form project
-
web.config
<authentication mode="Forms"> <forms name=".ADAuthCookie" timeout="10" /> </authentication>
-
specify users
<authorization> <deny users="?" /> <allow users="*" /> </authorization>
This configuration allows only authenticated users to access the application. The “?” indicates unauthenticated users and the “*” indicates all users. By denying unauthenticated users, any requests made by unauthenticated users are redirected to your login page. The loginUrl attribute on the
element determines the name of the login page. The default setting of this attribute in Machine.config.comments is Login.aspx -
Next, configure the Web Application to Use ActiveDirectoryMembershipProvider. configure ASP.NET Membership providers for multiple domains in Web.config file
<connectionStrings> <add name="TestDomain1ConnectionString" connectionString="LDAP://testdomain1.test.com/CN=Users,DC=testdomain1,DC=test,DC=com" /> <add name="TestDomain2ConnectionString" connectionString="LDAP://testdomain2.test.com/CN=Users,DC=testdomain2,DC=test,DC=com" /> <add name="TestDomain3ConnectionString" connectionString="LDAP://testdomain3.test.com/CN=Users,DC=testdomain3,DC=test,DC=com" /> </connectionStrings>
here, we add connection strings that point to your Active Directory user database for each domain.
-
Then, configure the
element with ActiveDirectoryMembershipProvider instances pointing to each domain as shown here. <membership > <providers> <add name="TestDomain1ADMembershipProvider" type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="TestDomain1ConnectionString" connectionUsername="testdomain1\administrator" connectionPassword="password"/> <add name="TestDomain2ADMembershipProvider" type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="TestDomain2ConnectionString" connectionUsername="testdomain2\administrator" connectionPassword="password"/> <add name="TestDomain3ADMembershipProvider" type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="TestDomain3ConnectionString" connectionUsername="testdomain3\administrator" connectionPassword="password"/> </providers> </membership>
Make sure you set the connectionStringName attribute to the correct connection string name specified earlier in your
section. -
todo: https://msdn.microsoft.com/en-us/library/ff650307.aspx
Windows Authentication
ASP.NET
-
Create a windows form project > Properties > Directory Security tab > Anonymous access and authentication control > Authentication Methods > select Integrated Windows authentication
-
web.config
<authentication mode="Windows" />
-
Enter username and password in the format:
DomainName\User Name
-
After logged in, we can access user info:
User.Identity.Name
-
Restrict access set authorization to the application by adding settings in the Web.config file. We can specify which users or groups are permitted to have access to what resources as follows:
To permit all users of an NT Group named Managers to have access to your resources, use the following code:
<configuration> <system.web> <authorization> <allow roles="domainname\Managers" /> <deny users="*" /> </authorization> </system.web> </configuration>
To permit only specific users to have access, use the following code:
<configuration> <system.web> <authorization> <allow users="domainname\user1,domainname\user2,domainname\user3" /> <deny users="*" /> </authorization> </system.web> </configuration>
Reference
https://msdn.microsoft.com/en-us/library/ff650307.aspx
-
Previous
Asynchronous programming tutorial in Angular -
Next
Command & Rollback design pattern practice