HttpContext.Current.Response inside a static method

Viewed 17661

I have the following static method inside a static class. My question is it safe to use HttpContext.Current.Response inside a static method? I want to be 100% sure that it is thread safe and is only associated with the calling thread.. Does anybody know the answer?

    public static void SetCookie(string cookieName, string cookieVal, System.TimeSpan ts)
    {
        try
        {
            HttpCookie cookie = 
                new HttpCookie(CookiePrefix + cookieName) 
                    {Value = cookieVal, Expires = DateTime.Now.Add(ts)};
            HttpContext.Current.Response.Cookies.Add(cookie);
        }
        catch (Exception)
        {
            return;
        }
    }
3 Answers
Related