2011-09-29 55 views
0

我實現窗體身份驗證一樣(我需要從Active Directory或從數據庫中無法創建基於某些某些條件票)如何實現餅乾的票據驗證時,我們創造我們自己的cookie

FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, 
     "userName", 
     DateTime.Now, 
     DateTime.Now.AddMinutes(30), // value of time out property 
     false, // Value of IsPersistent property 
     String.Empty, 
     FormsAuthentication.FormsCookiePath); 

string encryptedTicket = FormsAuthentication.Encrypt(ticket); 
HttpCookie authCookie = new HttpCookie(
          FormsAuthentication.FormsCookieName, 
          encryptedTicket); 

authCookie.Secure = true; 
Response.Cookies.Add(authCookie); 

and my web.config 


<system.web> 
    <authentication mode="Forms"> 
    <forms loginUrl="Login.aspx" 
      protection="All" 
      timeout="30" 
      name="test" 
      path="/" 
      requireSSL="false" 
      slidingExpiration="true" 
      cookieless="UseDeviceProfile" 
      enableCrossAppRedirects="false" /> 
    </authentication> 
</system.web> 

這如果啓用瀏覽器cookie,則實施工作正常。而它當禁用Cookie不工作(我試過無Cookie =「useuri」,但它不幫助)

可以請你們告訴我,我應該如何在這種情況下

我想用實施cookiless窗體身份驗證uri的auth cookie或其他更好的解決方案?

+0

所以,你想在一個cookie的環境中使用cookies嗎? :S –

+0

將它存儲在會話中它是一個cookie,但Cookie駐留在Web服務器上 – CBRRacer

+0

我想用戶uri,但它不起作用,因爲我認爲我將cookie添加到響應對象@Ranhiru – Grasshopper

回答

相關問題