惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
爱范儿
爱范儿
WordPress大学
WordPress大学
博客园 - 三生石上(FineUI控件)
J
Java Code Geeks
Vercel News
Vercel News
aimingoo的专栏
aimingoo的专栏
T
Tailwind CSS Blog
罗磊的独立博客
B
Blog
博客园_首页
A
About on SuperTechFans
有赞技术团队
有赞技术团队
V
V2EX
U
Unit 42
I
InfoQ
IT之家
IT之家
博客园 - 司徒正美
阮一峰的网络日志
阮一峰的网络日志
博客园 - 叶小钗
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Stack Overflow Blog
Stack Overflow Blog
The Cloudflare Blog
H
Help Net Security

博客园 - 欢欢

写在跌后C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\PrivateAssembliesC:\Program Files\Microsoft SQL Server\MSSQL.4\Reporting Services\ReportServer\bin - 欢欢 恋家 ASP.net操作Word的提示拒绝访问或open不动 查询数据库中满足条件的特定行数据 默林 微软对联 好可爱的星座!(转) - 欢欢 - 博客园 爱因斯坦谜题解答(三种算法比较) w3wp.exe的进程占用了100% 今天也碰到这个问题,参考下面方法搞好了,非常感谢 CS0016: 未能写入输出文件 无线网络技术在物流管理中应用--家乐福大型连锁超市的应用案例 让无线使用更安全 无线设置详解 string code length .NET开源范例汇集贴 .NET Pet Shop 4.0.msi下载[.NET多层架构]地址 VS2005的中文版下载地址 http://thinhunan.cnblogs.com/favorite/42604.html NBear Project NHibernate学习之路
高效的Session读写.
欢欢 · 2006-05-15 · via 博客园 - 欢欢

private static User currentUser = null;
        
/// <summary>
        
/// 当前用户
        
/// </summary>

        public static User CurrentUser{
            
get{
                
if(currentUser != null && HttpContext.Current.Session["LoginUser"!= null)
                    
return currentUser;
                
                
if(HttpContext.Current.Session["LoginUser"!= null){
                    currentUser 
= (User)HttpContext.Current.Session["LoginUser"];
                    
return currentUser;
                }


                
if(currentUser != null && HttpContext.Current.Session["LoginUser"== null){
                    
return currentUser;
                }

                
//没有登陆的用户,自动读取cookie登陆
                currentUser = new PopForum.Common.Entity.User();
                HttpCookie c 
= HttpContext.Current.Request.Cookies["UserInfo"];
                
if(c!=null && c.Value!=""){
                    FormsAuthenticationTicket ticket 
= FormsAuthentication.Decrypt(c.Value);
                    Common.DataMapping.UserInfo info 
= null;
                    Users users 
= new Users();
                    
int r = users.CheckUser(ticket.Name,out info);
                    
if(r==1){
                        currentUser.UserId 
= info.UserId;
                        currentUser.UserName 
= info.UserName;
                        currentUser.Status 
= (Common.UserStatus)info.UserStatus;
                        currentUser.Point 
= info.Point;
                        DataTable table 
= DataBase.ExecuteSQLTable("select rr.rightid from t_roleright rr,t_userrole ur where rr.roleid=ur.roleid and ur.userid="+currentUser.UserId.ToString());
                        
foreach(DataRow row in table.Rows){
                            currentUser.Rights.Add((Common.Right)row[
"rightid"]);
                        }

                        
//判断用户是否有系统管理权限
                        if(currentUser.HaveRight(Common.Right.SiteAdmin)){
                            
//更新用户登陆信息
                            users.LoginUpdate(ref info,currentUser);
                            currentUser.Point 
= info.Point;
                            Sessioner.Add(
"LoginUser",currentUser);
                        }

                            
//判断网站是否关闭,但管理员可以登陆
                        else if(Common.Configs.ForumConfig.SiteConfiger.CloseFlag){
                            
throw new CtyException("网站被关闭,暂时无法访问",DealType.RediretErrorPage);
                        }

//                            //判断是否允许登陆
//                        else if(!Common.Configs.ForumConfig.SiteConfiger.LoginFlag){
//                            throw new CtyException("登陆被禁止,暂时无法登陆",DealType.RediretErrorPage);
//                        }
                        else{
                            users.LoginUpdate(
ref info,currentUser);
                            currentUser.Point 
= info.Point;
                            Sessioner.Add(
"LoginUser",currentUser);
                        }

                    }

                }
else{
                    
//匿名用户
                    if(!Common.Configs.ForumConfig.SiteConfiger.AnonymousFlag)
                        
throw new CtyException("网站不允许匿名用户访问",DealType.RediretErrorPage);
                }

                
return currentUser;
            }
set{
                 Sessioner.Add(
"LoginUser",value);
                 currentUser 
= value;
             }

        }