ASP.NET MVC 实现简单的登录
程序员文章站
2022-05-03 14:00:20
1、创建一个控制器 如下: 2、视图界面 抱歉第一次写博客 感觉有点说不清的感觉.... ......
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>
抱歉第一次写博客 感觉有点说不清的感觉....