Reputation: 61
I'm developing web in Asp.Net Mvc5. But today suddenly I can't login /Using identity/.
Here's my login action:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Login(LoginViewModel input, string returnUrl)
{
if (ModelState.IsValid)
{
string personalNo = AppStaticConfig.ServiceController.PupilLogin(input.Code, input.Password, ModelState);
if (!string.IsNullOrEmpty(personalNo))
{
PupilProfile pp = AppStaticConfig.ServiceController.PupilDetail(personalNo, AppStaticConfig.SchoolID, ModelState);
var identity = new ClaimsIdentity(new[] {
new Claim(ClaimTypes.Name, pp.pupil.LastName.Substring(0, 1) + "." + pp.pupil.FirstName),
new Claim(ClaimTypes.NameIdentifier, personalNo),
new Claim("pupilCode", input.Code)
},
DefaultAuthenticationTypes.ApplicationCookie,
ClaimTypes.Name, ClaimTypes.Role);
identity.AddClaim(new Claim(ClaimTypes.Role, "guest"));
Authentication.SignIn(new AuthenticationProperties{ IsPersistent = true }, identity);
TempData["pp"] = pp;
return RedirectToAction("PupilProfile", "Pupil");
}
}
return View(input);
}
And here's Pupil controller's PupilProfile action which redirected after successful login:
[Authorize]
public class PupilController : Controller
{
[HttpGet]
public ActionResult PupilProfile()
{
PupilProfile pp = TempData["pp"] != null ? TempData["pp"] as PupilProfile : AppStaticConfig.ServiceController.PupilDetail(User.Identity.GetUserId(), AppStaticConfig.SchoolID, ModelState);
return View(pp);
}
}
I think the problem is User.Identity not setting in Authentication.SignIn
.
Any1 has idea what's wrong?
Upvotes: 0
Views: 1584
Reputation: 61
Problem solved. Was some environment problem I think.
What I was tried to fix:
Hope it help some1.
Upvotes: 2