I am trying to set a h4 subheading displayed in the top area of the login page. Its been hard-coded as in code below in Login.cshtml.
<h4>Use a local account to log in.</h4>
I want to use something like below, where this.Model refers to the LoginViewModel for the Login view.
<h4 id="loginHeading">@this.Model.LoginSubHeading </h4>
The LoginViewModel is as below.
public class LoginViewModel
{
[Required]
[Display(Name = "Email")]
[EmailAddress]
public string Email { get; set; }
[Required]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password { get; set; }
[Display(Name = "Remember me?")]
public bool RememberMe { get; set; }
public string LoginSubHeading {get;set;} = "Use a local account to log in."
}
The problem I am facing is that I don't want to make an extra database trip in the Login method of AccountController class to get the setting value for LoginSubHeading, but would like to fetch this setting from the database in the same database trip being made for verifying credentials. I am not using external authentication but accounts stored in a SQL Server databse. Also, I am using the standard inbuilt security/login that comes with ASP.Net MVC5. The standard Login method in AccountController class is as below.
// POST: /Account/VerifyCode
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> VerifyCode(VerifyCodeViewModel model)
{
if (!ModelState.IsValid)
{
return View(model);
}
// The following code protects for brute force attacks against the two factor codes.
// If a user enters incorrect codes for a specified amount of time then the user account
// will be locked out for a specified amount of time.
// You can configure the account lockout settings in IdentityConfig
var result = await SignInManager.TwoFactorSignInAsync(model.Provider, model.Code, isPersistent: model.RememberMe, rememberBrowser: model.RememberBrowser);
switch (result)
{
case SignInStatus.Success:
return RedirectToLocal(model.ReturnUrl);
case SignInStatus.LockedOut:
return View("Lockout");
case SignInStatus.Failure:
default:
ModelState.AddModelError("", "Invalid code.");
return View(model);
}
}