ASP.NET MVC 实现简单的登录
发布时间:2020-12-16 09:26:25 所属栏目:asp.Net 来源:网络整理
导读: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 { // /
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 分页显示数据表的数据的代码
- ef-code-first – 如何通过使用Identity ASP.NET MVC的代码
- asp.net – 向GridView添加默认排序箭头
- asp.net-mvc – LINQ Distinct()
- asp.net-mvc-3 – SignalR依赖注入问题
- ASP.NET MVC – 查看主页,如何设置标题?
- ASP.NET TreeView控件的使用
- asp.net – 在.net中输入密钥和多个提交按钮
- asp.net – 如何将javascript文件的服务限制为仅经过身份验
- asp.net-mvc – 仍然在存储库和解耦,ASP.NET MVC上丢失
推荐文章
站长推荐
- ASP.NET MVC – 返回JavaScriptResult不起作用
- API Test WebApiTestClient工具安装及使用
- asp.net-mvc-3 – Razor reseverd words
- asp.net-core – 如何自动增加MVC 6版本号?
- asp.net-mvc – 在Hub,SignalR之外获取connectio
- 经典的ASP脚本超时
- asp.net – 为customvalidator设置errormessage?
- asp.net-core – 使用.NET Core时需要AssemblyIn
- ASP.NET Azure中的Trace.WriteLine
- ASP.NET:它是否涉及Active X?
热点阅读