ASP.NET MVC 实现简单的登录
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了ASP.NET MVC 实现简单的登录,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1970字,纯文字阅读大概需要3分钟。
内容图文
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>
抱歉第一次写博客 感觉有点说不清的感觉....
内容总结
以上是互联网集市为您收集整理的ASP.NET MVC 实现简单的登录全部内容,希望文章能够帮你解决ASP.NET MVC 实现简单的登录所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。