1、创建一个控制器   如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Demo.Models; //命名空间 namespace Demo.Controllers
{
public class HomeController : Controller
{
//
// GET: /Home/
DL_DemoEntities db = new DL_DemoEntities(); //模型 public ActionResult Index() //首页
{
return View();
}
public ActionResult Demo404() //登陆失败跳转
{
return View();
}
public ActionResult Start_Here() //登陆成功跳转
{
return View();
}
[HttpPost]
public ActionResult Login(string name, string password)
{
name = Request["name"];
password = Request["password"];
if (string .IsNullOrEmpty(name)||string .IsNullOrEmpty(password))
{
return Content("<script>alert('账号密码不能为空');location.href='Demo404'</script>"); }
else
{
var user = db.User.Where(u => u.admin == name && u.passid == password).SingleOrDefault();
if (user == null)
{
return Content("<script>alert('输入有误');location.href='Demo404'</script>"); }
else
{
return Content("<script>location.href='Start_Here'</script>");
//登录成功跳转
}
} } }
}

2、视图界面

<body style="background:url(Html/images/bg.jpg) no-repeat;">
<form action="/Home/Login" method="post"> <div class="container wrap1" style="height:450px;">
<h2 class="mg-b20 text-center">单木不林后台登录页面</h2>
<div class="col-sm-8 col-md-5 center-auto pd-sm-50 pd-xs-20 main_content">
<p class="text-center font16">用户登录</p>
<form>
<div class="form-group mg-t20">
<i class="icon-user icon_font"></i>
<input type="text" class="login_input" id="Email1" name="name" placeholder="请输入用户名" />
</div>
<div class="form-group mg-t20">
<i class="icon-lock icon_font"></i>
<input type="password" class="login_input" id="Password1" name="password" placeholder="请输入密码" />
</div>
<div class="checkbox mg-b25">
<label>
<input type="checkbox" />记住我的登录信息
</label>
</div>
<button type="submit" class="login_btn">登 录</button>
</form>
</div><!--row end-->
</div><!--container end-->
</form> </body>

  界面

百度云:https://pan.baidu.com/s/1zY8Hhwrnc5adkVg_TLirzw   提取码:ytnw

ASP.NET MVC 实现简单的登录的更多相关文章

  1. Easyui + asp.net MVC 系列教程 完成登录

    Easyui + asp.net MVC 系列教程 第09-17 节 完成登录 高清录制 前面八节 在这里 Easyui + asp.net mvc + sqlite 开发教程(录屏)适合入门 在接下 ...

  2. ASP.NET MVC项目演练:用户登录

    ASP.NET MVC 基础入门 http://www.cnblogs.com/liunlls/p/aspnetmvc_gettingstarted.html 设置默认启动页面 public clas ...

  3. ASP.NET MVC下判断用户登录和授权的方法

    日常开发的绝大多数系统中,都涉及到管理用户的登录和授权问题.登录功能(Authentication),针对于所有用户都开放:而授权(Authorization),则对于某种用户角色才开放. 在asp. ...

  4. asp.net mvc 实现简单的实时消息推送

    因为项目需要,需要在网页上实现消息的推送.在百度上搜索了一下,发现实现网页上的消息推送,可以使用asp.net 中的SignalR类库,当然也可以使用H5的WebSocket  Ajax的轮回.当然此 ...

  5. ASP.NET MVC下判断用户登录和授权状态方法

    在我们日常开发的绝大多数系统中,都涉及到管理用户的登录和授权问题.登录功能(Authentication),针对于所有用户都开放:而授权(Authorization),则对于某种用户角色才开放. 在a ...

  6. asp.net mvc(一) ----------简单封装成通用的List<T>集合

    asp.net mvc(一) 这些天开始学习asp.net mvc,用传统的asp.net已经快四的年了,刚开始接触asp.net mvc确认感觉有点不适应,主要体现在asp.net mvc的实现上. ...

  7. ASP.Net MVC Filter验证用户登录

    一.Filter是什么 ASP.NetMVC模式自带的过滤器Filter,是一种声明式编程方式,支持四种过滤器类型,各自是:Authorization(授权),Action(行为),Result(结果 ...

  8. ASP.NET MVC使用AuthenticationAttribute验证登录

    首先,添加一个类AuthenticationAttribute,该类继承AuthorizeAttribute,如下: using System.Web; using System.Web.Mvc; n ...

  9. asp.net mvc 三层加EF 登录注册 增删改查

    首先打开vs软件新建项目创建web中的mvc项目再右击解决方案创建类库项目分别创建DAL层和BLL层再把DAL层和BLL层的类重命名在mvc项目中的Models文件夹创建model类在DAL创建ADO ...

随机推荐

  1. Taro聊天室|react+taro仿微信聊天App界面|taro聊天实例

    一.项目简述 taro-chatroom是基于Taro多端实例聊天项目,运用Taro+react+react-redux+taroPop+react-native等技术开发的仿微信App界面聊天室,实 ...

  2. Android监视器概述

    还望支持个人博客站:http://www.enjoytoday.cn Android监视器可帮助您分析应用程序的性能,以便您优化,调试和改进它们. 它可以让您从硬件设备或Android模拟器监控应用程 ...

  3. Java collection 集合类架构

    https://www.cnblogs.com/fireflyupup/p/4875130.html Collection List 在Collection的基础上引入了有序的概念,位置精确:允许相同 ...

  4. 类,接口,final

    继承extends 子类实例化过程: 子类中所有的构造方法默认都会访问父类中空参的构造方法 因为每一个子类的构造方法的提议行都有一条默认的语句super(); this super final修饰类, ...

  5. [20190823]关于CPU成本计算2.txt

    [20190823]关于CPU成本计算2.txt --//前几天探究CPU cost时遇到的问题,获取行成本时我的测试查询结果出现跳跃,不知道为什么,感觉有点奇怪,分析看看.--//ITPUB原始链接 ...

  6. excel如何快速选中某个区域

    一.问题 excel如何快速选中某个区域 二.解决 如图:要选中A1-D12的区域,可以选择用鼠标,单数数据量多的时候就比较麻烦,可以用下面这种方式.

  7. Python入门基础学习(函数)

    Python基础学习笔记(三) 函数的概念: 所谓函数,就是把具有独立功能的代码块组织为一个小模块,在需要的时候调用 函数的使用包含两个步骤: 1.定义函数 --封装独立的功能 2.调用函数 --享受 ...

  8. 16.Java基础_对象内存图

    单个对象 1.进入main函数,生成main函数的栈空间 2.先在mian函数的栈空间里产生一个Student变量(以后会用来存储Studnet对象的首地址),然后进入Student类,在堆内存创建S ...

  9. c# WF 第8节 label控件

    本节内容: 1: 文本控件 2:实现label的你追我赶实例 1:文本控件 2:实现label的你追我赶实例 步骤1 : 步骤2 : 知识点:

  10. springboot中Thymeleaf和Freemarker模板引擎的区别

    前言这两个都是属于模板引擎,但是各有各的好处,enn,在市面上比较多的也就是jsp.freemarker.velocity.thymeleaf等页面方案.Thymeleaf和Freemarker的区别 ...