• Entity Framwork(EF) 7——在Controller内获取指定字段的值


    一、开发背景:

      在用户登录的时候,验证用户和密码是否正确。验证通过后将用户名和用户ID保存下来以便后续数据更新时使用。

    二、用户验证方法:

      1、创建DBContext 对象。

       ApplicationDbContext _context;

       //Controller构造函数
            public FramController(ApplicationDbContext context)
            {
                _context = context;
            }

      2、查询数据库。

      var users = from u in _context.UserInfo
                                    where u.User_Account == "system"
                                    select u;

      3、验证用户密码是否正确,并获取用户ID。

      if(users.Count()>0)
                        {
                            String pwd = users.First().User_Pwd;  //获取用户密码
                            if (pwd == Command.Md5Helper(ul.Password))  //验证密码是否正确
                                Command.UserId = users.First().User_ID.ToString();  //获取用户ID
                            else  //验证失败返回用户登录页面并显示“用户名或密码错误!”
                                return Redirect("/Home/Index?UserName=" + ul.UserAccount + "&log= username or password erro!"+Command.Md5Helper(ul.Password));
                        }

  • 相关阅读:
    WPF 模拟UI 键盘录入
    rabbitmq使用dead letter机制来进行retry
    工厂设计模式
    python 内置速度最快算法(堆排)
    简单工厂设计模式
    杂类
    MorkDown 常用语法总结
    使用python列表推导式进行99乘法表
    linux 命令free -m 命令结果分析
    理解记忆三种常见字符编码:ASCII, Unicode,UTF-8
  • 原文地址:https://www.cnblogs.com/Roxlin/p/5514721.html
Copyright © 2020-2023  润新知