static 变量问题
public static string GetCookieVal(string sKey)
{
string sRe = string.Empty;
try
{
HttpCookie cookie = HttpContext.Current.Request.Cookies[CookieKey];
if (cookie != null) {
sRe = cookie[sKey];
}
}
catch
{ }
return sRe;
}
public static string UserName { get { return GetCookieVal("username"); } }
请问在页面中使用 UserName这个变量会有问题吗?会不会读到别人的Cookie??? --------------------编程问答-------------------- 上页那个 CookieKey 已经定义了的。
public static readonly string CookieKey = "UserInfo";--------------------编程问答-------------------- 静态属性和静态字段可不是一回事 --------------------编程问答--------------------
请问我上面的用法可否有问题???? --------------------编程问答-------------------- 肯定不会,你傻啊 --------------------编程问答-------------------- 静态方法里,只要没有对共享数据(例如托管堆上的对象)做修改,那么它是线程安全的 --------------------编程问答-------------------- cook是保存在用户本地的吧! --------------------编程问答-------------------- 静态方法里存的cook 都一样的吧
补充:.NET技术 , ASP.NET