我在静态类中有以下静态方法。我的问题是在静态方法中使用 HttpContext.Current.Response 是否安全?我想 100% 确定它是线程安全的,并且只与调用线程相关联。有人知道答案吗?
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;
}
}