Asp.net的安全認證及Web.config的配置

1)在Web.config的配置   
   在<system.web>中修改選項
     驗證模式設爲Form,並且驗證頁爲
      <authentication mode="Forms">
        <forms loginUrl="Login.aspx" />
      </authentication>
     不允許匿名用戶
      <authorization>
        <deny users="?" />
      </authorization>

   在</system.web>後加入不要驗證就能使用數據庫的頁面,用於在該頁訪問數據庫,察看是否存在該用戶。
     <location path="Reg.aspx">
       <system.web>
         <authorization>
           <allow users="*"/>
         </authorization>
       </system.web>
     </location>

  (2)在代碼中按普通方式,例如要求對方輸入信息查找數據庫或者XML進行驗證,驗證通過後,執行這句就表示驗證通過同時跳會開始進入的頁面
      System.Web.Security.FormsAuthentication.RedirectFromLoginPage(userName,true);
      註銷用 System.Web.Security.FormsAuthentication.SignOut();  
      如果不想跳回原處,可以先授權再redirect到其他頁面  System.Web.Security.FormsAuthentication.SetAuthCookie(); 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章