c# 对于下面代码怎么运行,新手不会弄

qq_35413838 2016-06-25 07:47:47
源程序代码
namespace Common {
public class PageManager:Admin.UserManager
{
/// 用户状态
public UserState AdminState { get; set; }
/// 用户名
protected string UserName { get; set; }
/// 密码
protected string UserPwd { get; set; }
/// 验证码
protected string CodeWord { get; set; }
/// 登录方式

这些源代码,怎么样让他在vs13中创建asp运行呢
...全文
132 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
coolsummer1006 2016-06-25
  • 打赏
  • 举报
回复
代码差的有点你多! 继承的父类因为完全没有信息,无从参考只看出来下面几点 object obj = GetState(SetPassWord(UserPwd), SetUserName(UserName), CodeWord); 不存在含有三个变量的此方法 Pwd = hmacmd.GetMd5pwd(hmacmd, Pwd); 不存在此方法,需要自己根据HMAC MD5 自己添加 其它的额应该没有什么了,例如Else ,Enum 缺少降等等,就只有你自己慢慢调了 public partial class PageManager1 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } //******************************************* //定义私有变量 private string PageUrl; private string LoginState; //******************************************* /// 用户状态 public UserState AdminState { get; set; } /// 用户名 protected string UserName { get; set; } /// 密码 protected string UserPwd { get; set; } /// 验证码 protected string CodeWord { get; set; } /// 登录方式 public string PageRedirect { get { return PageUrl; } } public string LoginInfo { get { return LoginState; } } private object cache { get; set; } /// 当前登录用户信息 public Object Cache { get { return cache; } } //application.CaCheUserData c = new application.CaCheUserData(true); // pageManager的构造函数 public PageManager1() { if (!IsPostBack) { this.Init += new EventHandler(PageManager_Init); this.Load += new EventHandler(PageManager_Load); } } public PageManager1(bool back) { } public PageManager1(string userName, string userPwd, string code) { UserName = userName; UserPwd = userPwd; CodeWord = code; Manager(); } private void Manager() { ///缓存当前用户信息 object obj = 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; } } protected virtual void PageManager_Load(object s, EventArgs e) { ///页面载时操作 if (Cache == null) GetUserData(); } /// 获取用户的状态 private void GetState() { 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; } } } public virtual void PageManager_Init(object sender, EventArgs e) { ///判断用户状态 GetState(); //当前页面不会缓存 Response.Expires = 0; Response.ExpiresAbsolute = DateTime.Now.AddMinutes(-1); Response.AddHeader("pragma", "no-cache"); Response.AddHeader("cache-control", "private"); Response.CacheControl = "no-cache"; } /// 用户状态 public enum UserState { online, leave, off, error } /// 获取登录号 public string GetUserName() { GetState(); if (AdminState == UserState.online) { return Session["app_user"].ToString(); } else { return null; } } /// 获取?用户主页 public string GetPageUrl() { GetState(); if (AdminState == UserState.online) { return Session["app_pageUrl"].ToString(); } else { return null; } } /// 获取用户信息 public void GetUserData() { this.cache = c.returnValue(GetUserName()); } public string SetPassWord(string Pwd) { string c = System.Configuration.ConfigurationManager.AppSettings["pwdnumber"]; byte[] b = System.Text.Encoding.UTF8.GetBytes(c); HMACMD5 hmacmd = new HMACMD5(b); Pwd = hmacmd.GetMd5pwd(hmacmd, Pwd); return Pwd; } public string SetUserName(string Name) { string d = System.Configuration.ConfigurationManager.AppSettings["usernumber"]; byte[] t = t = System.Text.Encoding.UTF8.GetBytes(d); HMACMD5 hmacmd = new HMACMD5(t); Name = hmacmd.GetMd5pwd(hmacmd, Name); return Name; } public void LoginOut() { ///在应用程序中清除该用户的信息 if (System.Web.HttpContext.Current.Application["TheUserLine"] != null) { string[] str = System.Web.HttpContext.Current.Application["TheUserLine"].ToString().Split('|'); string temp = ""; for (int i = 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"); } }
EdsionWang 2016-06-25
  • 打赏
  • 举报
回复
真的,你不要再研究这段代码了。找本ASP.Net的书,把基础的知识看看搞明白。这是一个Page的后台代码,里面还封装了一堆东西。你根本没法简单的建一个aspx页面去实现所谓的效果(仅仅提供这一点代码的话)。 刚刚看了一个帖子,很适合初学者借鉴。 http://bbs.csdn.net/topics/391957249
qq_35413838 2016-06-25
  • 打赏
  • 举报
回复
namespace Common { public class PageManager:Admin.UserManager { /// 用户状态 public UserState AdminState { get; set; } /// 用户名 protected string UserName { get; set; } /// 密码 protected string UserPwd { get; set; } /// 验证码 protected string CodeWord { get; set; } /// 登录方式 public string PageRedirect { get { return PageUrl; } } public string LoginInfo { get { return LoginState; } } private object cache { get; set; } /// 当前登录用户信息 public Object Cache { get { return cache; } } application.CaCheUserData c = new application.CaCheUserData(true); // pageManager的构造函数 public PageManager() { if (!IsPostBack) { this.Init += new EventHandler(PageManager_Init); this.Load+=newEventHandler(PageManager_Load); } } public PageManager(bool back) { } public PageManager(string userName,string userPwd,string code) { UserName = userName; UserPwd = userPwd; CodeWord = code; Manager(); } private void Manager() { ///缓存当前用户信息 object obj = 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; } } protected virtual void PageManager_Load(object s, EventArgs e) { ///页面载时操作 if (Cache == null) GetUserData(); } /// 获取用户的状态 private void GetState() { 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; } } public virtual void PageManager_Init(object sender, EventArgs e) { ///判断用户状态 GetState(); //当前页面不会缓存 Response.Expires = 0; Response.ExpiresAbsolute = DateTime.Now.AddMinutes(-1); Response.AddHeader("pragma","no-cache"); Response.AddHeader("cache-control","private"); Response.CacheControl = "no-cache"; } /// 用户状态 public enum UserState { online, leave, off, Error } /// 获取登录号 public string GetUserName() { GetState(); if (AdminState == UserState.online) { return Session["app_user"].ToString(); } Else { return null; } } /// 获取?用户主页 public string GetPageUrl() { GetState(); if (AdminState == UserState.online) { return Session["app_pageUrl"].ToString(); } Else { return null; } } /// 获取用户信息 public void GetUserData() { this.cache = c.returnValue(GetUserName()); } public string SetPassWord(string Pwd) { string c = System.Configuration.ConfigurationManager.AppSettings["pwdnumber"]; byte[] b = System.Text.Encoding.UTF8.GetBytes(c); HMACMD5 hmacmd = new HMACMD5(b); Pwd = hmacmd.GetMd5pwd(hmacmd, Pwd); return Pwd; } public string SetUserName(string Name) { string d = System.Configuration.ConfigurationManager.AppSettings["usernumber"]; byte[] t = t = System.Text.Encoding.UTF8.GetBytes(d); HMACMD5 hmacmd = new HMACMD5(t); Name = hmacmd.GetMd5pwd(hmacmd, Name); return Name; } public void LoginOut() { ///在应用程序中清除该用户的信息 if (System.Web.HttpContext.Current.Application["TheUserLine"] != null) { string[] str = System.Web.HttpContext.Current.Application["TheUserLine"].ToString().Split('|'); string temp = ""; for (int i = 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"); } } } 就只有这些源代码
EdsionWang 2016-06-25
  • 打赏
  • 举报
回复
新手就多看书多看源代码,东抄一句西凑一句就像看到什么效果。
全栈极简 2016-06-25
  • 打赏
  • 举报
回复
创建一个模型类PageManager,把代码复制进去。 但是这个类继承了Admin.UserManager ,那么Admin.UserManager在哪里你就要确认一下。 看懂了代码再动手。

62,266

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧