C# 我需要在自定义mvc登录页面和仪表板显示用户详细信息和pic MVC4的帮助
我现在是一名学生,我正在学习MVC4。我在MVC中设计了一个自定义网站,有一个自定义的用户登录表单和仪表板 我已经创建了一个带有电子邮件、密码和重新编号复选框的登录文件 之后,我有下面这样的代码C# 我需要在自定义mvc登录页面和仪表板显示用户详细信息和pic MVC4的帮助,c#,model-view-controller,razor,C#,Model View Controller,Razor,我现在是一名学生,我正在学习MVC4。我在MVC中设计了一个自定义网站,有一个自定义的用户登录表单和仪表板 我已经创建了一个带有电子邮件、密码和重新编号复选框的登录文件 之后,我有下面这样的代码 模型代码 public class Login { [Required(ErrorMessage = "Please Enter E-mail.")] [DataType(DataType.EmailAddress)
public class Login
{
[Required(ErrorMessage = "Please Enter E-mail.")]
[DataType(DataType.EmailAddress)]
[StringLength(150)]
public string Email { get; set; }
[Required(ErrorMessage = "Please Enter Password.")]
[DataType(DataType.Password)]
[StringLength(30, MinimumLength = 6)]
public string Password { get; set; }
}
[HttpGet] public ActionResult Login()
{
return View();
}
#region Login Model
[HttpPost]
public ActionResult Login(Models.MessageGroup.Login User)
{
if (ModelState.IsValid)
{
if (IsValid(User.Email, User.Password))
{
FormsAuthentication.SetAuthCookie(User.Email, false);
return RedirectToAction("Dashboard", "User");
}
else
{
ModelState.AddModelError("error", "Please check Login details are incorrect.");
}
}
return View(User);
}
在web.config中使用此代码
<authentication mode="Forms">
<forms loginUrl="Login.cshtml" protection="All" timeout="30" name=".ASPXAUTH"
path="/" requireSSL="false" slidingExpiration="true" defaultUrl="Index.cshtml"
cookieless="UseDeviceProfile" enableCrossAppRedirects="false" /> </authentication>
它将返回
@User.Identity.Name
在web.config中使用此代码
<authentication mode="Forms">
<forms loginUrl="Login.cshtml" protection="All" timeout="30" name=".ASPXAUTH"
path="/" requireSSL="false" slidingExpiration="true" defaultUrl="Index.cshtml"
cookieless="UseDeviceProfile" enableCrossAppRedirects="false" /> </authentication>
它将返回
@User.Identity.Name
如果您已经启用了Identity,那么它在web.config中可能有如下配置:
<system.webServer>
<modules>
<remove name="FormsAuthenticationModule" />
</modules>
</system.webServer>
您必须删除该行如果您已经启用了Identity,则它可能在web.config中具有如下配置:
<system.webServer>
<modules>
<remove name="FormsAuthenticationModule" />
</modules>
</system.webServer>
您必须删除该行它的帮助以获取@User.Identity.Name中的登录值,该行不在开发自定义登录之后。它的帮助以@User.Identity.Name中的登录值获取@User.Identity.Name中的登录值,该登录值不在开发自定义登录之后