记住这些
-HttpContext.Current
-Foreach
我很难把我的头缠在这上面…这个代码在asp.net中是“线程安全”的吗?

public static bool IsCookieMissing()
{
    foreach (string cookieKey in HttpContext.Current.Request.Cookies.AllKeys)
    {
        if (cookieKey.EndsWith("cookie_name"))
        {
            return false;
        }
    }
    return true;
}

最佳答案

这个代码在asp.net中是“线程安全”的吗?
这取决于你期望它做什么。它很可能做了您期望做的事情,所以它是“线程安全的”,除非您正在启动自己的线程来调用它。HttpContext.Current是调用它的当前HttpContext。您不需要担心this question中链接到的问题-您不使用任何闭包。

09-30 15:49
查看更多