问题描述
源程序代码namespaceCommon{publicclassPageManager:Admin.UserManager{///用户状态publicUserStateAdminState{get;set;}///用户名protectedstringUserName{get;set;}///密码protectedstringUserPwd{get;set;}///验证码protectedstringCodeWord{get;set;}///登录方式这些源代码,怎么样让他在vs13中创建asp运行呢
解决方案
解决方案二:
创建一个模型类PageManager,把代码复制进去。但是这个类继承了Admin.UserManager,那么Admin.UserManager在哪里你就要确认一下。看懂了代码再动手。
解决方案三:
新手就多看书多看源代码,东抄一句西凑一句就像看到什么效果。
解决方案四:
namespaceCommon{publicclassPageManager:Admin.UserManager{///用户状态publicUserStateAdminState{get;set;}///用户名protectedstringUserName{get;set;}///密码protectedstringUserPwd{get;set;}///验证码protectedstringCodeWord{get;set;}///登录方式publicstringPageRedirect{get{returnPageUrl;}}publicstringLoginInfo{get{returnLoginState;}}privateobjectcache{get;set;}///当前登录用户信息publicObjectCache{get{returncache;}}application.CaCheUserDatac=newapplication.CaCheUserData(true);//pageManager的构造函数publicPageManager(){if(!IsPostBack){this.Init+=newEventHandler(PageManager_Init);this.Load+=newEventHandler(PageManager_Load);}}publicPageManager(boolback){}publicPageManager(stringuserName,stringuserPwd,stringcode){UserName=userName;UserPwd=userPwd;CodeWord=code;Manager();}privatevoidManager(){///缓存当前用户信息objectobj=GetState(SetPassWord(UserPwd),SetUserName(UserName),CodeWord);if(LoginState==System.Configuration.ConfigurationManager.AppSettings.Get("onlineteach")){Session["app_user"]=UserName;Session["app_pageUrl"]=PageUrl;AdminState=UserState.online;///缓存在线人员System.Web.HttpContext.Current.Application.Lock();System.Web.HttpContext.Current.Application["TheUserLine"]+=Session.SessionID+":"+UserType+"&"+UserName+"|";System.Web.HttpContext.Current.Application.UnLock();///将用户信息缓存应运程序中c.cache_name=UserName;c.CreateCache(obj);System.Web.Security.FormsAuthentication.SetAuthCookie(UserName,false);}Else{AdminState=UserState.error;}}protectedvirtualvoidPageManager_Load(objects,EventArgse){///页面载时操作if(Cache==null)GetUserData();}///获取用户的状态privatevoidGetState(){Try{if(AdminState!=UserState.online||Session["app_user"]==null){LoginOut();AdminState=UserState.off;}}Catch{AdminState=UserState.off;}Finally{if(UserState.off==AdminState){System.Web.HttpContext.Current.Response.Redirect("/Application/login.aspx");}ElseAdminState=UserState.online;}}publicvirtualvoidPageManager_Init(objectsender,EventArgse){///判断用户状态GetState();//当前页面不会缓存Response.Expires=0;Response.ExpiresAbsolute=DateTime.Now.AddMinutes(-1);Response.AddHeader("pragma","no-cache");Response.AddHeader("cache-control","private");Response.CacheControl="no-cache";}///用户状态publicenumUserState{online,leave,off,Error}///获取登录号publicstringGetUserName(){GetState();if(AdminState==UserState.online){returnSession["app_user"].ToString();}Else{returnnull;}}///获取?用户主页publicstringGetPageUrl(){GetState();if(AdminState==UserState.online){returnSession["app_pageUrl"].ToString();}Else{returnnull;}}///获取用户信息publicvoidGetUserData(){this.cache=c.returnValue(GetUserName());}publicstringSetPassWord(stringPwd){stringc=System.Configuration.ConfigurationManager.AppSettings["pwdnumber"];byte[]b=System.Text.Encoding.UTF8.GetBytes(c);HMACMD5hmacmd=newHMACMD5(b);Pwd=hmacmd.GetMd5pwd(hmacmd,Pwd);returnPwd;}publicstringSetUserName(stringName){stringd=System.Configuration.ConfigurationManager.AppSettings["usernumber"];byte[]t=t=System.Text.Encoding.UTF8.GetBytes(d);HMACMD5hmacmd=newHMACMD5(t);Name=hmacmd.GetMd5pwd(hmacmd,Name);returnName;}publicvoidLoginOut(){///在应用程序中清除该用户的信息if(System.Web.HttpContext.Current.Application["TheUserLine"]!=null){string[]str=System.Web.HttpContext.Current.Application["TheUserLine"].ToString().Split('|');stringtemp="";for(inti=0;i<str.Length;i++){if(str[i].IndexOf(Session.SessionID)!=-1){temp=str[i];break;}}if(!string.IsNullOrEmpty(temp))System.Web.HttpContext.Current.Application["TheUserLine"]=System.Web.HttpContext.Current.Application["TheUserLine"].ToString().Replace(temp+"|","");}Session.Clear();AdminState=UserState.off;System.Web.Security.FormsAuthentication.SignOut();System.Web.HttpContext.Current.Response.Redirect("/Application/login.aspx");}}}就只有这些源代码
解决方案五:
真的,你不要再研究这段代码了。找本ASP.Net的书,把基础的知识看看搞明白。这是一个Page的后台代码,里面还封装了一堆东西。你根本没法简单的建一个aspx页面去实现所谓的效果(仅仅提供这一点代码的话)。刚刚看了一个帖子,很适合初学者借鉴。
解决方案六:
代码差的有点你多!继承的父类因为完全没有信息,无从参考只看出来下面几点objectobj=GetState(SetPassWord(UserPwd),SetUserName(UserName),CodeWord);不存在含有三个变量的此方法Pwd=hmacmd.GetMd5pwd(hmacmd,Pwd);不存在此方法,需要自己根据HMACMD5自己添加其它的额应该没有什么了,例如Else,Enum缺少降等等,就只有你自己慢慢调了publicpartialclassPageManager1:System.Web.UI.Page{protectedvoidPage_Load(objectsender,EventArgse){}//*******************************************//定义私有变量privatestringPageUrl;privatestringLoginState;//*******************************************///用户状态publicUserStateAdminState{get;set;}///用户名protectedstringUserName{get;set;}///密码protectedstringUserPwd{get;set;}///验证码protectedstringCodeWord{get;set;}///登录方式publicstringPageRedirect{get{returnPageUrl;}}publicstringLoginInfo{get{returnLoginState;}}privateobjectcache{get;set;}///当前登录用户信息publicObjectCache{get{returncache;}}//application.CaCheUserDatac=newapplication.CaCheUserData(true);//pageManager的构造函数publicPageManager1(){if(!IsPostBack){this.Init+=newEventHandler(PageManager_Init);this.Load+=newEventHandler(PageManager_Load);}}publicPageManager1(boolback){}publicPageManager1(stringuserName,stringuserPwd,stringcode){UserName=userName;UserPwd=userPwd;CodeWord=code;Manager();}privatevoidManager(){///缓存当前用户信息objectobj=GetState(SetPassWord(UserPwd),SetUserName(UserName),CodeWord);if(LoginState==System.Configuration.ConfigurationManager.AppSettings.Get("onlineteach")){Session["app_user"]=UserName;Session["app_pageUrl"]=PageUrl;AdminState=UserState.online;///缓存在线人员System.Web.HttpContext.Current.Application.Lock();System.Web.HttpContext.Current.Application["TheUserLine"]+=Session.SessionID+":"+UserType+"&"+UserName+"|";System.Web.HttpContext.Current.Application.UnLock();///将用户信息缓存应运程序中c.cache_name=UserName;c.CreateCache(obj);System.Web.Security.FormsAuthentication.SetAuthCookie(UserName,false);}else{AdminState=UserState.error;}}protectedvirtualvoidPageManager_Load(objects,EventArgse){///页面载时操作if(Cache==null)GetUserData();}///获取用户的状态privatevoidGetState(){try{if(AdminState!=UserState.online||Session["app_user"]==null){LoginOut();AdminState=UserState.off;}}catch{AdminState=UserState.off;}finally{if(UserState.off==AdminState){System.Web.HttpContext.Current.Response.Redirect("/Application/login.aspx");}else{AdminState=UserState.online;}}}publicvirtualvoidPageManager_Init(objectsender,EventArgse){///判断用户状态GetState();//当前页面不会缓存Response.Expires=0;Response.ExpiresAbsolute=DateTime.Now.AddMinutes(-1);Response.AddHeader("pragma","no-cache");Response.AddHeader("cache-control","private");Response.CacheControl="no-cache";}///用户状态publicenumUserState{online,leave,off,error}///获取登录号publicstringGetUserName(){GetState();if(AdminState==UserState.online){returnSession["app_user"].ToString();}else{returnnull;}}///获取?用户主页publicstringGetPageUrl(){GetState();if(AdminState==UserState.online){returnSession["app_pageUrl"].ToString();}else{returnnull;}}///获取用户信息publicvoidGetUserData(){this.cache=c.returnValue(GetUserName());}publicstringSetPassWord(stringPwd){stringc=System.Configuration.ConfigurationManager.AppSettings["pwdnumber"];byte[]b=System.Text.Encoding.UTF8.GetBytes(c);HMACMD5hmacmd=newHMACMD5(b);Pwd=hmacmd.GetMd5pwd(hmacmd,Pwd);returnPwd;}publicstringSetUserName(stringName){stringd=System.Configuration.ConfigurationManager.AppSettings["usernumber"];byte[]t=t=System.Text.Encoding.UTF8.GetBytes(d);HMACMD5hmacmd=newHMACMD5(t);Name=hmacmd.GetMd5pwd(hmacmd,Name);returnName;}publicvoidLoginOut(){///在应用程序中清除该用户的信息if(System.Web.HttpContext.Current.Application["TheUserLine"]!=null){string[]str=System.Web.HttpContext.Current.Application["TheUserLine"].ToString().Split('|');stringtemp="";for(inti=0;i<str.Length;i++){if(str[i].IndexOf(Session.SessionID)!=-1){temp=str[i];break;}}if(!string.IsNullOrEmpty(temp))System.Web.HttpContext.Current.Application["TheUserLine"]=System.Web.HttpContext.Current.Application["TheUserLine"].ToString().Replace(temp+"|","");}Session.Clear();AdminState=UserState.off;System.Web.Security.FormsAuthentication.SignOut();System.Web.HttpContext.Current.Response.Redirect("/Application/login.aspx");}}