我正在开发一个ASP.Net MVC 3应用程序使用C#和SQL Server 2005.我使用实体框架与代码优先的方法。部分视图空页面ASP MVC 3
我有一个LOG ON(连接)的接口,它与我的基地相关,我有一个USER表(包含登录名+密码)。
这是联接的视图: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。其次,我不确定“连接成功”的意思(我认为,登录成功),但如果是这种情况,则表示您没有正确认证用户。 – 2013-05-10 08:53:20
是的,登录successeded这是我的意思。我认为认证是正确的,因为当我把基数中存在的值放到一个带有LogOn链接的页面上时。然而,在相反的情况下,它带我到一个空白页面 – anouar 2013-05-10 09:06:27
这个逻辑应该在你的控制器而不是你的页面。代码在您的账户控制器中看起来像什么? – 2013-05-10 09:30:36