1

My model is

public class Login
{
    [Required]
    [Display(Name = "Email")]
    [EmailAddress]
    public string Email { get; set; }

    [Required]
    [DataType(DataType.Password)]
    [Display(Name = "Password")]
    public string Password { get; set; }


}

My Post method is

    [HttpPost]
    public ActionResult Login(Models.Login lu)
    {
        using (travelAndTourismEntities objentity = new travelAndTourismEntities())
        {
            if (ModelState.IsValid)
            {
                if (IsValid(lu.Email, lu.Password))
                {
                    FormsAuthentication.SetAuthCookie(lu.Email, true);
                    return RedirectToAction("Home", "jettravel");
                }
                else
                {
                    ModelState.AddModelError("", "Login details are wrong.");
                }
            }
            return View(lu);
        }
    }

In view

@if (Request.IsAuthenticated)
{
     <div class="col-md-3 col-sm-3 col-xs-12" style=" font-size:14px; ">
     <div class="header_info">
     <p class="login_username">Welcome <span>@Html.Encode(User.Identity.Name)</span></p>
}

I want to display customer email in view, but @if (Request.IsAuthenticated) is always getting false

tmg
  • 19,895
  • 5
  • 72
  • 76
Richa
  • 41
  • 1
  • 6

1 Answers1

1

Try replacing this line

<p class="login_username">Welcome <span>@Html.Encode(User.Identity.Name)</span></p>

with

<p class="login_username">Welcome <span>@HttpContext.Current.User.Identity.Name;</span></p>
Itniv
  • 112
  • 2
  • 2
  • 11
  • actually @if (Request.IsAuthenticated) is always getting false it is not getting a true value – Richa Jan 28 '16 at 08:59
  • Have you check whether the SetAuthentication cookie is being set or not.. if its being set the try changing it to FormsAuthentication.SetAuthCookie(lu.Email, false); and try it should work – Itniv Jan 28 '16 at 10:55