Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有以下代码:
HttpCookie myCookie = new HttpCookie("PopMsgText"); myCookie.Value = message; Response.Cookies.Add(myCookie);
它在响应行给出 NullReferenceException。可能是什么原因?
属性Cookies或Response对象为空。这可能会发生,具体取决于您调用此代码的位置。例如,如果您尝试Response在后台线程中访问对象,则它可能为 null,因为没有与后台线程关联的 HttpContext。
Cookies
Response