任务:
利用表单服务器发送一个用户名和密码,如果正确,返回欢迎您;否则返回错误。
login.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<form action="Hello/Login" method="post">//method用来隐藏密码
用户名:<input type="text" name="name" />
密码:<input type="text" name="pwd" />
<input type="submit" value="登 录"/>
</form>
</body>
</html>
HelloController.cs
//HelloController.cs
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace ChapterOne.Controllers
{
public class HelloController : Controller
{
public IActionResult Login(String name,String pwd)
{
if (name == "Tom" && pwd == "123")
return Content("Hello," + name);
else
return Content("error");
}
}
}