Answered by:
SetAuthCookie not working

Question
-
User-1771888428 posted
hello,
I uninstalled owin and identity completely from my mvc 5 web api 2 application so that I use forms authentication my web.config file portion is:
<authentication mode="Forms"> <forms loginUrl="~/Account/LogOn" timeout="2880" defaultUrl="~/" /> </authentication>
and the mvc account controller is:
public ViewResult LogOn() { return View(new LogOnModel { UserName = "", Password = "", RememberMe = false }); } [HttpPost] public ActionResult LogOn(LogOnModel model) { string returnUrl = ""; if (Request.QueryString["ReturnUrl"] != null) returnUrl = Request.QueryString["ReturnUrl"].ToString(); if (ModelState.IsValid) { if (Membership.ValidateUser(model.UserName, model.Password)) { FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe); //bool isauth = User.Identity.IsAuthenticated; if (returnUrl == "") return RedirectToAction("Index", "Home"); else return Redirect(returnUrl); } else { ModelState.AddModelError("", "The user name or password provided is incorrect."); return View(model); } } else { return View(model); } } public ActionResult SignOut() { FormsAuthentication.SignOut(); return RedirectToAction("Index", "Home"); }
membership validate is successful (code portion:
Membership.ValidateUser(model.UserName, model.Password)
) but when code wants to Set the auth cookie it does nothing, and when I check the HttpContext.Current.User.Identity.IsAuthenticated in _Layout, it returns false.
I also added the following appsetting to webconfig so that if any of owin components still remains it is prevented from interfering with forms authentication.
<add key="owin:AutomaticAppStartup" value="false" />
What is the problem causing this?
Sunday, November 9, 2014 1:12 AM
Answers
-
User-1771888428 posted
I find the solution, I commented out the following line in web.config and authentication succeeds:
<system.webServer> <modules> <!--<remove name="FormsAuthentication" />--> </modules> <handlers> ...
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Sunday, November 9, 2014 6:41 AM
All replies
-
User-1716253493 posted
Afaik to use cookie simply set rememberme to true.Sunday, November 9, 2014 2:02 AM -
User-1771888428 posted
I find the solution, I commented out the following line in web.config and authentication succeeds:
<system.webServer> <modules> <!--<remove name="FormsAuthentication" />--> </modules> <handlers> ...
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Sunday, November 9, 2014 6:41 AM