關於FormsAuthentication.RedirectFromLoginPage() context.user.Identity.name

 看別人的代碼,發現下面一句  
   FormsAuthentication.RedirectFromLoginPage(userId,    false);  
   能重定向至另一頁面,但這裏並沒有指定要轉向那個頁面啊,
原來在web.config有配置啊
[code]<authentication    mode="Forms"    >    
   <forms    loginUrl="login.aspx"></forms>  
   </authentication>  
   <authorization>  
   <deny    users="?"/>  
   </authorization> [/code] 
呵呵,這個東西很爽的,當用了FORM認證,如果你沒有登錄,不管你打開的哪頁,都會進入指定的登錄頁面,登錄完成後,又能返回你指定的頁...


authentication    mode="Forms"    >    
   <forms    loginUrl="login.aspx"></forms>  
   </authentication>  
   -----------------------------上面是身份驗證的  
   -----------------下面是授權的  
   <authorization>  
   <deny    users="?"/>  
   </authorization>  
   
   將已驗證身份的用戶重定向回最初請求的    URL

 

爲什麼context.user.Identity.name總是爲空??
 建立一個IHttpModule並且在web.config註冊它。
然後在Cookies或Session裏記錄了用戶的標記,
在每次的Application.AxxxxxRequest(英文不知怎寫,驗證請求)時,根據Cookies,Session的信息重新做一次context.user=new   Myprincipal(userId);

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章