Quantcast
Channel: CodeProject Latest postings for ASP.NET
Viewing all articles
Browse latest Browse all 3938

ASP.Net MVC: Request.IsAuthenticated getting false after successfully login

$
0
0
i am using asp.net MVC and identity to authenticate user. i saw after successfully authenticate
Request.IsAuthenticated returnfalse

this is sample login code which i debug and saw it is working fine.
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
publicasync Task<ActionResult> Login(LoginViewModel model, string returnUrl)
{
    if (!ModelState.IsValid)
    {
        return View(model);
    }
 
    // This doesn't count login failures towards account lockout
// To enable password failures to trigger account lockout, change to shouldLockout: true
var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false);
    switch (result)
    {
        case SignInStatus.Success:
            return RedirectToLocal(returnUrl);
        case SignInStatus.LockedOut:
            return View("Lockout");
        case SignInStatus.RequiresVerification:
            return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe });
        case SignInStatus.Failure:
        default:
            ModelState.AddModelError("", "Invalid login attempt.");
            return View(model);
    }
}

after successfully login page redirect to home index action where i am showing user information in index view like below way but controls never come there because of Request.IsAuthenticated return false
<div class="row">
    <div class="col-md-12">
        @{
            if (Request.IsAuthenticated)
            {
                var manager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()));
                var currentUser = manager.FindById(User.Identity.GetUserId());
                <p>@currentUser.UserName</p>

just do not understand what i am missing for which request authenticate method always returning false. please help me to fix it. thanks
tbhattacharjee

Viewing all articles
Browse latest Browse all 3938

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>