⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 index.aspx.cs

📁 用asp.net开发的考试系统
💻 CS
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.Security;
using System.Configuration;

namespace examonline
{
    public partial class index : System.Web.UI.Page
    {

        protected void Page_Load(object sender, System.EventArgs e)
        {
           
            // 在此处放置用户代码以初始化页面
        }

        #region Web 窗体设计器生成的代码
        override protected void OnInit(EventArgs e)
        {
            //
            // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
            //
            InitializeComponent();
            base.OnInit(e);
        }

        /// <summary>
        /// 设计器支持所需的方法 - 不要使用代码编辑器修改
        /// 此方法的内容。
        /// </summary>
        private void InitializeComponent()
        {

        }
        #endregion

        private void login()
        {
            string conn = ConfigurationManager.AppSettings["strconn"];
            //string mpsw = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(txtpsw.Text, "MD5");MD5加密
            string sql = "select * from yonghu where username='" + txtid.Text.Trim() + "' and password='" + txtpsw.Text.Trim() + "'";
            SqlConnection cn = new SqlConnection(conn );
            SqlCommand cmd = new SqlCommand(sql, cn);
            SqlDataReader dr;
            try
            {
                cn.Open();
                dr = cmd.ExecuteReader();
                if (dr.Read())
                {
                    Session["UserID"] = dr.GetValue(0);
                    Session["UserName"] = dr.GetString(1);
                    Session["indenty"] = dr.GetValue(3);
                    Session["IsLogined"] = true;
                    Session["kaoti"] = false;
                    Response.Redirect("showexam.aspx");
                }
                else
                {
                    lblmsg.Text = "用户名或密码错误!";
                }
            }
            catch (SqlException ex)
            {
                lblmsg.Text = "数据库错误:" + ex.Message.ToString();
            }
            finally
            {
                cn.Close();
            }
        }
        protected void btnlogin_Click(System.Object sender, System.EventArgs e)
        {
          // if (txtcode.Text == (string)Session["vali"])
         // {
                login();
          // }
         //  else
        //  {
           //  lblmsg.Text = "所填写的验证码与所给的不符!";
        // }
        }


    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -