2013-12-21 36 views
1

我正在使用下面的代碼來刪除特定的cookie。它的工作更早。但現在不行。出現錯誤HttpContext.Current爲空。我無法猜測爲什麼現在發生。請澄清我。HttpContext.Current爲空

if (HttpContext.Current.Request.Cookies[name] != null{ 
    HttpContext.Current.Request.Cookies.Remove(name); 
} 

請幫我解決這個問題。

+0

您是否在本地主機或外部IIS服務器上測試您的應用程序? – whoah

+0

本地主機和服務器也 – user3085540

+0

在本地主機和服務器得到了同樣的錯誤 – user3085540

回答

-1

試試這個。

HttpCookieCollection MyCookieCollection = Request.Cookies; 
HttpCookie MyCookie = MyCookieCollection.Get(name); 
if (MyCookie != null) 
{ 
    HttpContext.Current.Request.Cookies.Remove(name); 
} 
+0

我得到了錯誤。對象引用未設置爲對象的實例 – user3085540

+0

再次嘗試我做了一些更改。 –

+0

不工作相同的錯誤 – user3085540

相關問題