2013-12-20 69 views
0

我有設置過的用戶認證數據一個cookie:對象引用錯誤

HttpContext.Current.Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(ticket))); 

現在,當我嘗試讀取使用另一個類的餅乾:

HttpCookie myCookie = new HttpCookie(FormsAuthentication.FormsCookieName); 
myCookie = HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName]; 

我收到一個Object reference not set to an instance of an object錯誤。
我檢查了我的瀏覽器cookie和.ASPXAUTH cookie與數據。

任何人都可以告訴我哪裏出錯了嗎?我試着兩個requestresponse

編輯:HttpContext.Current.Request.Cookies.Get返回相同的錯誤

EDIT2:好像HttpContext.Currentnull

回答

0

.NET 4.5有一些問題閱讀HttpContext.Current

Reading this answer,將以下內容添加到您的web.config

<system.serviceModel> 
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/> 
</system.serviceModel>