• 技术文章 >后端开发 >C#.Net教程

    .net实现后台登录验证

    Y2JY2J2017-05-12 10:15:59原创833
    这篇文章主要为大家详细介绍了.net后台页面统一验证是否登录的方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

    本文实例为大家分享了.net后台页面统一验证是否登录的具体代码,供大家参考,具体内容如下

    首先新写一个PageBase类

    using System;
    using System.Collections.Generic;
    using System.Web;
    
    namespace DepartmentMIS.Web.myclass
    {
      public class PageBase : System.Web.UI.Page
      {
        public PageBase()
        {
          this.Load += new EventHandler(BasePage_Load);
        }
    
        private void BasePage_Load(object sender, EventArgs e)
        {
          if (Session["UserNo"] == null || Session["UserNo"].ToString() == "")
          {
            Response.Redirect("~/Login.aspx");
          }
        }
      }
    }

    Login页面后台部分代码

    protected void btnLogin_Click(object sender, EventArgs e)
        {
          if (rblRole.SelectedValue == "1")
          {
            DataSet ds = AdminBLL.GetList("userName = '" + tbxUserName.Text.Trim() + "' and password = '" + tbxPassword.Text.Trim()+"' and isDeleted = 0");
            if (ds.Tables[0].Rows.Count == 1)
            {
              int id = Convert.ToInt32(ds.Tables[0].Rows[0]["id"]);
              Session["UserNo"] = ds.Tables[0].Rows[0]["id"];
              Session["UserName"] = ds.Tables[0].Rows[0]["userName"];
              Response.Redirect("admin/adminIndex.aspx");
            }
            else
            {
              Response.Write("<script>alert('用户名或密码错误!')</script>");
            }
          }
          if (rblRole.SelectedValue == "2")
          {
            DataSet ds = StuBLL.GetList("stuNo = '" + tbxUserName.Text.Trim() + "' and password = '" + tbxPassword.Text.Trim() + "' and isDeleted = 0");
            if (ds.Tables[0].Rows.Count == 1)
            {
              int id = Convert.ToInt32(ds.Tables[0].Rows[0]["id"]);
              Session["UserNo"] = ds.Tables[0].Rows[0]["id"];
              Session["UserName"] = ds.Tables[0].Rows[0]["stuName"];
              Response.Redirect("student/stusIndex.aspx");
            }
            else
            {
              Response.Write("<script>alert('用户名或密码错误!')</script>");
            }
          }

    以stuWishChoices页面为例,继承PageBase类

    using System.Web.UI.WebControls.WebParts;
    using System.Data.SqlClient;
    using System.Collections;
    
    namespace cbmis.ProDocumentMng
    {
      public partial class DocumentList : BasePage //继承
      {
          protected void Page_Load(object sender, EventArgs e)
          {
        
          }
    
        }
      }
    }

    【相关推荐】

    1. ASP免费视频教程

    2. ASP教程

    3. 李炎恢ASP基础视频教程

    php入门到就业线上直播课:查看学习

    以上就是.net实现后台登录验证的详细内容,更多请关注php中文网其它相关文章!

    声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。

    前端(VUE)零基础到就业课程:点击学习

    清晰的学习路线+老师随时辅导答疑

    自己动手写 PHP MVC 框架:点击学习

    快速了解MVC架构、了解框架底层运行原理

    专题推荐:.net 验证 登录,后台
    上一篇:VS2017完成静态库的搭建 下一篇:自己动手写 PHP MVC 框架(40节精讲/巨细/新人进阶必看)

    相关文章推荐

    • ❤️‍🔥共22门课程,总价3725元,会员免费学• ❤️‍🔥接口自动化测试不想写代码?• c语言中源文件编译后生成什么文件• c语言标识符有哪些类型• asp.net 图片验证码的HtmlHelper• 解决asp.net中“从客户端中检测到有潜在危险的Request.Form值”的错误• C#中GDI+编程10个基本技巧二
    1/1

    PHP中文网