ASP.NET Tutorial/Configuration/authentication
Содержание
- 1 Allowing a single user through the web.config file
- 2 Denying all users through the web.config file
- 3 Modifying the web.config file to add username/password values
- 4 Specify all users with the use of the asterisk (*)
- 5 The <authentication> Node
- 6 To allow more than one user
- 7 web.config file for forms-based authentication
Allowing a single user through the web.config file
<source lang="csharp">
<configuration>
<system.web> <authentication mode="Windows" /> <allow users="DomainName\Bill" /> <deny users="*" /> </authorization> </system.web>
</configuration></source>
Denying all users through the web.config file
<source lang="csharp">
<configuration>
<system.web> <authentication mode="Windows" /> <authorization> <deny users="*" /> </authorization> </system.web>
</configuration></source>
Modifying the web.config file to add username/password values
<source lang="csharp">
<system.web>
<authentication mode="Forms"> <forms name="Wrox" loginUrl="Login.aspx" path="/"> <credentials passwordFormat="Clear"> <user name="userName" password="Bubbles" /> </credentials> </forms> </authentication> <authorization> <deny users="?" /> </authorization>
</system.web></source>
Specify all users with the use of the asterisk (*)
<source lang="csharp">
<configuration>
<system.web> <authentication mode="Windows" /> <allow roles="*" /> </authorization> </system.web>
</configuration></source>
The <authentication> Node
<source lang="csharp">
<configuration>
<system.web> <authentication mode="Windows|Forms|Passport|None"> </authentication> </system.web>
</configuration></source>
To allow more than one user
<source lang="csharp">
<configuration>
<system.web> <authentication mode="Windows" /> <allow users="MyDomain\User1" /> <allow users="MyDomain\User2" /> </authorization> </system.web>
</configuration>
or you can use the following: <configuration>
<system.web> <authentication mode="Windows" /> <allow users="MyDomain\User1, MyDomain\User2" /> </authorization> </system.web>
</configuration></source>
web.config file for forms-based authentication
<source lang="csharp">
<system.web>
<authentication mode="Forms"> <forms name="formName" loginUrl="Login.aspx" path="/" /> </authentication> <authorization> <deny users="?" /> </authorization>
</system.web></source>