ASP.NET MVC5 代码如下:
namespace mhqNetAPP.Web.Areas.APPAPI.Controllers
{
public class LoginController : Controller
{
// GET: APPAPI/Login 用户登录
public ActionResult Index(string username,string password)
{
if(username=="mhq"&&password=="123")
{
return Json(new { status = "y", info = "恭喜你登录成功!" }, JsonRequestBehavior.AllowGet);
//登录成功
}
else
{
return Json(new { status = "n", info = "登录失败!" }, JsonRequestBehavior.AllowGet);
}
}
}
}
ASP.NET Core 代码如下:
namespace mhqNetAPP.Web.Areas.appapi.Controllers
{
[Area("appapi")] //路由机制详见https://gist.github.com/MartinWuQing/fda27ba52f9d3163de03f3511f359615
public class loginController : Controller
{
// GET: APPAPI/Login 用户登录
public ActionResult Index(string username, string password)
{
if (username == "mhq" && password == "123")
{
return Json(new { status = "y", info = "恭喜你登录成功!" });
//登录成功
}
else
{
return Json(new { status = "n", info = "登录失败!" });
}
}
}
}