나는 ADO.net을 사용하여 ASP MVC를 개발 중입니다. 사용자 로그인 후 로그인 필드를 숨기려고합니다.숨겨진 방법 로그인 한 사용자로부터 로그인 필드
실제로 홈 페이지의 인증 후에 사용자는 프로필 페이지로 리디렉션됩니다. 문제는 사용자가 홈 페이지로 돌아갈 때 항상 로그인 필드를 찾는다는 것입니다.
디버거에 따르면 세션 [ "currentUser"]은 항상 null로 유지되고 스크립트가 렌더링됩니다.
dev 도구에서도 오류를 찾지 못했습니다.
@if (Session["currentUser"] != null)
{
<script type='text/javascript'>
$(document).ready(function(){
$("#login").hide();
});
</script>
}
<div class="login" id="login">
@*@RenderPage("~/Views/Home/Login.cshtml")*@
<link href="~/Content/toastr.css" rel="stylesheet" />
<div class="main-w3l">
<div class="w3layouts-main" style="background-image:url('/template/web/images/bg3.jpg'); margin-top:50px;">
<h2>Login Now</h2>
@using (Html.BeginForm("Login", "Home", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<input value="E-MAIL" name="Email" type="email" required="" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'E-Mail';}" />
<input value="PASSWORD" name="Password" type="password" required="" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'password';}" />
<span><input type="checkbox" />Remember Me</span>
<h6><a href="#">Forgot Password?</a></h6>
<div class="clear"></div>
<input type="submit" value="login" name="login">
}
<p>Don't Have an Account ?<a href="#" onclick="@("window.location.href='" + @Url.Action("Create", "Client") + "'") ;">Register Now</a></p>
</div>
</div>
UPDATE : 컨트롤러 :
public ActionResult Login()
{
return View();
}
database_Access_layer.db dblayer = new database_Access_layer.db();
[HttpPost]
public ActionResult Login(FormCollection fc, string LastName, string Email)
{
int res = dblayer.Admin_Login(fc["Email"], fc["Password"]);
if (res == 1)
{
Session["currentUser"] = Email;
string z = Email;
connection();
con.Open();
SqlCommand command = new SqlCommand("select Email from Client", con);
List<string> result = new List<string>();
using (var reader = command.ExecuteReader())
{
while (reader.Read())
result.Add(reader.GetString(0));
con.Close();
}
foreach (string x in result)
{
if (x == z)
{
SqlCommand command2 = new SqlCommand($"select LastName from Client WHERE Email= '{x}' ", con);
con.Open();
string y = command2.ExecuteScalar().ToString();
con.Close();
Session["currentUser"] = y;
}
}
return RedirectToAction("Profil", "Client");
Session.RemoveAll();
}
else {
TempData["msg"] = " Email or Password is wrong !";
return RedirectToAction("Index", "Home");
}
}
당신의 작업은 다음과 같이 보일 것인가? .net 코어 또는 .net 프레임 워크? –
mvc 5, .net 코어 – Exact
잘 mvc 5는 .net 코어가 아닙니다. .net 코어에는 mvc 6이 있고 mvc 5는 들어 있습니다.net framework –