I am having some issue using OWIN and the cookie authentication. To be clear, the cookie generated by OWIN is never sent to the browser. I know there is lots of post and answers already on this issue, but none are working for me. I am working in local environment, with ASP.NET Framework 4.5.2 and IIS 10, and the session is also used in the project. The ASP.NET_SessionId cookie is present.
Here are the different files I use in the authentication process :
Session_Start in Global.asax
Session["Dummy"] = "0";
Configuration in Startup.cs
ConfigureAuth(app);
ConfigureAuth in Startup.Auth.cs
app.UseKentorOwinCookieSaver(PipelineStage.Authenticate);
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Identification/Index"),
CookieManager = new SystemWebChunkingCookieManager(),
});
Upon submitting the form to log in, I check if the account is valid and, if so, I execute this code
Claim[] claims = new Claim[]
{
new Claim(ClaimTypes.Email, cpt.Login), // Email address
new Claim(ClaimTypes.Name, cpt.Identite.Nom), // User Name
new Claim(ClaimTypes.NameIdentifier, cpt.NumeroClient.ToString()) // Unique ID of user account
};
ClaimsIdentity userIdentity = new ClaimsIdentity(claims, DefaultAuthenticationTypes.ApplicationCookie);
IOwinContext owinContext = Request.GetOwinContext();
IAuthenticationManager owinAuthenticationManager = owinContext.Authentication;
owinAuthenticationManager.SignIn(new AuthenticationProperties() {
IsPersistent = true,
AllowRefresh = true,
ExpiresUtc = DateTime.Now.AddMonths(1)
}, userIdentity);
And then I redirect to the homepage
return RedirectToAction("Index", "Home");
But I can't see the cookie. I tried to add
<authentication mode="None"></authentication>
in the web.config under "system.web", still nothing. As you can see, I'm using the Kendor Cookie Saver, still does not work for me :( I tried to set a path, domain and secure to the cookie in the Startup.Auth.cs, also tried to implement my own cookie manager, but nothing does it.
Can you guys see something I missed ? Thanks for the help.
Also, this is my first post on stackoverflow, let me know if I have to improve it, there's always next time.
Here's Jimmy
Update
When creating a new MVC project, I have zero problems. I can see the ApplicationCookie, so it's got to be something with the current project I am working on (created almost 8 years ago). I tried to update/add any NuGet package so my packages.config file looks like the empty project, but still nothing. I am going to try some stuff on my own, so I can at least not use the session anymore, but it is very frustrating not to be able to use Owin's full potential of authentication :(