C# 및 SQL Server 2005를 사용하여 ASP.Net MVC 3 응용 프로그램을 개발 중입니다. 코드 우선 접근 방식으로 Entity Framework를 사용하고 있습니다.빈 페이지가있는 부분 뷰 ASP MVC 3
나는 USER 테이블 (Login + password 포함)이있는 내베이스와 관련된 LOG ON (연결)을위한 인터페이스를 가지고 있습니다.
이
는 접속의보기이다 LogonPartial.acx (강하게 UserViewModel에서 입력 부분보기)<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<MvcApplication2.ViewModels.UserViewModel>" %>
<%
if (Request.IsAuthenticated) {
%>
Welcome <strong><%: Page.User.Identity.Name %></strong>!
[ <%: Html.ActionLink("Log Off", "LogOff", "Account") %> ]
<%
}
else {
%>
[ <%: Html.ActionLink("Log On", "LogOn", "Account") %> ]
<%
}
%>
때 접속 성공 : 내가 링크 '에 로그인'에만 있습니다. 접속이 실패하면 : 페이지가 비어
이 컨트롤러입니다 :
[ChildActionOnly]
public ActionResult LogedInUser()
{
var user = new UserViewModel();
if (Request.IsAuthenticated)
{
user.Nom_User = User.Identity.Name;
}
return PartialView(user);
}
private GammeContext db = new GammeContext();
[AcceptVerbs(HttpVerbs.Post)]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings",
Justification = "Needs to take same parameter type as Controller.Redirect()")]
public ActionResult LogedInUser(string Matricule, string passWord, bool rememberMe, string returnUrl)
{
if (!ValidateLogOn(Matricule, passWord))
{
return Connection(Matricule, passWord, returnUrl);
}
//FormsAuth.SignIn(Matricule, rememberMe);
if (!String.IsNullOrEmpty(returnUrl))
{
return Redirect(returnUrl);
}
else
{
return RedirectToAction("Index", "Home");
}
}
public ActionResult Connection(string Matricule, string passWord, string returnUrl)
{
List<User> users = db.Users.ToList();
ActionResult output = null;
if (users.Any())
{
foreach (User u in users)
{
if ((u.Matricule == Matricule) && (u.passWord == passWord))
{
output = View();
}
}
}
else
{
output = Redirect(returnUrl);
}
return output;
}
그럼 첫 번째는 결코 심지어 UserViewModel을 사용하지 않는거야 - 나는 또한이 튜토리얼을 통해 이동 추천 할 것입니다. 두 번째로 나는 "연결 성공"(연결 성공이라고 가정)이 무엇을 의미하는지 확신 할 수 없지만, 그렇다면 올바른 사용자를 인증하지 않는 것입니다. –
예, 로그인이 성공했습니다. 베이스에 존재하는 값을 넣으면 LogOn 링크가있는 페이지로 이동하기 때문에 인증이 필요하다고 생각합니다. 그러나 반대의 경우에는 빈 페이지로 이동합니다. – anouar
이 논리는 귀하의 페이지가 아닌 컨트롤러에 있어야합니다. 계정 컨트롤러에서 코드는 어떻게 보이나요? –