MVC请求 处理 响应【用户登陆】
来源:互联网 发布:怎么打开手机网络 编辑:程序博客网 时间:2024/05/17 03:25
MVC路由设置 App_Start/RouteConfig.cs
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.Mvc;using System.Web.Routing;namespace Mvclogin{ public class RouteConfig { public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( name: "Default", url: "{controller}/{action}", defaults: new { controller = "Login", action = "Index" } ); } }}
控制器 Controllers/LoginController.cs
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.Mvc;using System.Data;using System.Data.SqlClient;namespace Mvclogin.Controllers{ public class LoginController : Controller { // // GET: /Login/ public ActionResult Index() { return View(); } public ActionResult Add() { string Name = Request["UserName"].ToString(); string Pass = Request["password"].ToString(); string sql = "insert into T_Login values(@userName,@pass)"; int i = SqlHelper.ExecuteNonQuery(sql, new SqlParameter("userName", Name), new SqlParameter("pass", Pass)); return Content("OK"); } public ActionResult Login() { return View("Login"); } public ActionResult LoginResponse() { string Name = Request.Form["UserName"].ToString(); string Pass = Request.Form["password"].ToString(); string sql = "select * from T_Login where UserName=@Name"; DataTable dt = SqlHelper.ExecuteDataTable(sql, new SqlParameter("Name", Name)); if (dt.Rows.Count <= 0) { ViewData["Message"] = "用户名不存在"; return View("Login"); } if (dt.Rows.Count > 1) { ViewData["Message"] = "大事不好,查询出多条数据"; return View("Login"); } if (dt.Rows[0]["password"].ToString() != Pass) { ViewData["Message"] = "密码错误啦"; return View("Login"); } return Content("恭喜你~登陆成功啦"); } }}
视图
Index视图 Views/Login/Index.aspx
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %><!DOCTYPE html><html><head runat="server"> <meta name="viewport" content="width=device-width" /> <title>用户注册</title></head><body> <div> <form method="post" action="/Login/Add"> <table> <tr> <tr><th>用户名:</th><td><input type="text" name="UserName" /></td></tr> <tr><th>密码:</th><td><input type="password" name="password" /></td></tr> <tr><td colspan="2" align="center"><input type="submit" value="注册" /></td></tr> </table> </form> </div></body></html>
Login视图 Views/Login/Login.aspx
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %><!DOCTYPE html><html><head runat="server"> <meta name="viewport" content="width=device-width" /> <title>Login</title></head><body> <div> <form method="post" action=/Login/LoginResponse> <table> <tr><th>用户名:</th><td><input type="text" name="UserName" /></td></tr> <tr><th>密码:</th><td><input type="password" name="password" /></td></tr> <tr><td colspan="2" align="center"> <input type="submit" value="登陆" /></td></tr> <tr><td colspan="2" align="center"> <span><%: ViewData["Message"] %></span></td></tr> </table> </form> </div></body></html>
0 0
- MVC请求 处理 响应【用户登陆】
- Servlet处理用户请求和响应(二)
- spring mvc 响应处理post请求和get请求 测试
- MVC 用户登陆验证
- MVC - 验证用户请求
- Spring MVC 请求响应流程
- spring MVC 请求响应流程
- MVC 用户登陆(验证码)
- MVC请求处理流程
- Spring mvc 请求处理
- Scoket 处理HTTP请求响应
- Servlet处理请求和响应
- 请求和响应编码处理
- Http协议请求响应处理
- web请求响应规范化处理
- mvc框架 请求到响应的过程。
- Servlet处理登陆响应参考代码
- Yii请求处理与响应处理
- 回调函数和虚接口使用的区别
- MDN404页的图片中眼睛的动画竟然是用CSS实现的
- 使用dbvisualizer报no jvm could be found on your system
- iOS应用程序生命周期(前后台切换,应用的各种状态)详解
- Java网络编程(http://52android.blog.51cto.com/2554429/482954)
- MVC请求 处理 响应【用户登陆】
- Linux下应用开源的库函数的时候 一定要 在两个文件中 注意
- 不显示界面的看护程序(看护进程)
- poj 1088滑雪
- poj 2253(3种最短路搞法)
- CSDN高校俱乐部有奖调查:实习就业需求调研
- 设计模式之模板方法模式
- dscp
- ngui 做技能冷却