qq_35413838 2016-06-25 12:37 采纳率: 0%
浏览 1380

对于源代码只有这些 怎么创建 在线答疑系统

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");
     }
 }

}

  • 写回答

1条回答 默认 最新

  • threenewbee 2016-06-25 15:13
    关注

    随便在工地捡了一块砖,现在问怎么盖一栋楼。这就是你的问题。

    评论

报告相同问题?

悬赏问题

  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献