ASP.NET Tutorial/Configuration/authentication

Материал из .Net Framework эксперт
Перейти к: навигация, поиск

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>