首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

各位大牛请进,本人小白,帮忙看段代码,多谢了!

2013-11-27 
各位大牛请进,本人小白,帮忙看段代码,谢谢了!!!!protected void btnLogin_Click (object sender, ImageCli

各位大牛请进,本人小白,帮忙看段代码,谢谢了!!!!
protected void btnLogin_Click (object sender, ImageClickEventArgs e)
{
     try
     {
          SqlParameter parameter1 = new SqlParameter("@Uid\uFFFD", SqlDbType.VarChar, 0x20);
          parameter1.Value = this.txtUid.Text.Trim();
          using(SqlDataReader reader1 = SqlHelper.ExecuteReader(ConfigurationManager.ConnectionStrings["SqlConStr\uFFFD"].ConnectionString, CommandType.Text, "select Pwd from T_User where Uid = @Uid\uFFFD", new SqlParameter[]{parameter1}))
          {
               if (reader1.Read() && (Encoding.ASCII.GetString(new MD5CryptoServiceProvider().ComputeHash(Encoding.ASCII.GetBytes(this.txtPwd.Text.Trim()))) == reader1["Pwd\uFFFD"].ToString()))
               {
                    SqlParameter[] parameterArray1 = new SqlParameter[]{new SqlParameter("@LastLoginDate\uFFFD", SqlDbType.DateTime), new SqlParameter("@LastLoginIP\uFFFD", SqlDbType.VarChar, 15), new SqlParameter("@Uid\uFFFD", SqlDbType.VarChar, 0x20)};
                    parameterArray1[0].Value = DateTime.Now;
                    parameterArray1[1].Value = base.Request.UserHostAddress;
                    parameterArray1[2].Value = this.txtUid.Text.Trim();
                    SqlHelper.ExecuteNonQuery(ConfigurationManager.ConnectionStrings["SqlConStr\uFFFD"].ConnectionString, CommandType.Text, "update T_User set LastLoginDate = @LastLoginDate, LastLoginIP = @LastLoginIP where Uid = @Uid\uFFFD", parameterArray1);
                    base.Response.Cookies["UserName\uFFFD"].Value = this.txtUid.Text.Trim();
                    if (this.ddlLoginState.SelectedIndex != 0)
                    {
                         base.Response.Cookies["UserName\uFFFD"].Value = this.txtUid.Text.Trim();
                         base.Response.Cookies["UserName\uFFFD"].Expires = DateTime.Now.AddDays((double) int.Parse(this.ddlLoginState.SelectedValue));
                    }
                    this.Session["UserName\uFFFD"] = this.txtUid.Text.Trim();
                    this.openWindow();
               }
               else
               {
                    this.Page.ClientScript.RegisterStartupScript(base.GetType(), "msgbox\uFFFD", "<script>window.alert('\u7528\u6237\u540D\u6216\u5BC6\u7801\u4E0D\u6B63\u786E\uFF01');document.getElementById('txtPwd').focus();</script>\uFFFD");
               }
          }
     }
     catch (Exception exception1)
     {
          File.AppendAllText(base.Server.MapPath("log\\error\uFFFD" + DateTime.Today.ToString("yyyyMMdd\uFFFD") + ".log\uFFFD"), string.Concat(new string[]{DateTime.Now.ToString("HH:mm\uFFFD"), " \u9875\u9762\uFF1A\uFFFD", base.Request.Url.ToString(), "\uFF1B\u4E8B\u4EF6\uFF1AbtnLogin_Click\uFF1B\u9519\u8BEF\u4FE1\u606F\uFF1A\uFFFD", exception1.Message, "\r\n\uFFFD"}));
     }
} C#语言


[解决办法]
这段代码的意思是:根据用户名到数据库中查询,如果有这个账号则记录当前登录的最后更新时间。记录界面选择的Cookie保留时间。并没有无权登录的代码。
[解决办法]
是发布的时候预编译过的。已经把aspx.cs编译成DLL了
[解决办法]

引用:
这段代码是这样的,您帮忙看看,这么改完以后是不是可以解除时间登录权限?
protected void Page_Load(object sender, EventArgs e)
    {
        if (DateTime.Today >= Convert.ToDateTime("2021-1-5"))
        {
            this.btnLogin.Visible = false;
        } 
        if (DateTime.Today >= Convert.ToDateTime("2021-1-6"))
        {
            Server.Transfer("NoPopedom.htm");
        }
        if (!Page.IsPostBack)
        {
            if (Request.Cookies["UserName"] != null 
[解决办法]
 Session["UserName"] != null)
            {
                //Response.Redirect("index.aspx");
                openWindow();
            }
            else
            {
                if (Request.Cookies["UserName"] != null)
                {
                    this.txtUid.Text = Request.Cookies["UserName"].Value;
                }
            }
        }
    }

至少2021年之前,这个页面没什么大问题

热点排行