【发布时间】:2021-04-16 20:13:24
【问题描述】:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Login</title>
</head>
<body>
<h3>User Login</h3>
@Model.Msg
<form method="post" asp-page="Login">
<table>
<tr>
<td>Email Address</td>
<td><input type="text" asp-for="@Model.Username" /></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" asp-for="@Model.Password" /></td>
</tr>
<tr>
<td>
Select whether you are a doctor or patient:
<p></p>
<input type="radio" id="doc" name="gender" value="Doctor">
<label for="doc">Doctor</label><br>
<input type="radio" id="pat" name="gender" value="Patient">
<label for="pat">Patient</label><br />
<tr>
<td> </td>
<td><input type="submit" value="Login" name="sub"/></td>
</tr>
</table>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using TeleHealthB.Models;
namespace TeleHealthB.Pages
{
public class LogInModel : PageModel
{
[BindProperty]
public string Username { get; set; }
[BindProperty]
public string Password { get; set; }
public string Msg { get; set; }
public void OnGet()
{
}
public IActionResult OnPost(string sub )
{
using (var context = new HealthProjectContext())
{
try
{
var query = from st in context.Patients
where st.Email == Username
select st.Password;
string check2 = query.FirstOrDefault();
if (Password.Equals(check2.Trim()))
{
HttpContext.Session.SetString("Username", Username);
return RedirectToPage("Welcome");
}
else
{
Msg = "Invalid";
return Page();
}
}
catch
{
Msg = "Invalid";
return Page();
}
}
}
}
}
此代码来自我正在处理的网站的其中一个剃须刀页面。该代码当前设置为将用户发送到一个通用登录页面的位置。我想让用户点击一个单选按钮来区分病人或医生并将他们发送到相应的网页。我对 asp.net 还很陌生,所以我不是 100% 可以做到这一点。
【问题讨论】: